Changeset 19028 for lang/ruby

Show
Ignore:
Timestamp:
09/09/08 02:14:21 (2 months ago)
Author:
drry
Message:
  • fixed regexps.
Location:
lang/ruby/nicovideo-post-ext/lib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/nicovideo-post-ext/lib/nicovideo-post-ext.rb

    r15307 r19028  
    2020        # getpostkey 
    2121        content = @agent.get_file(BASE_URL + "/api/getpostkey?thread=#{@params['thread_id']}&block_no=0") 
    22         @params.merge!(content.scan(/([^&]+)=([^&]*)/).inject({}){|h, v| h[v[0]] = v[1]; h}) 
     22        @params.merge!(content.scan(/([^&=]+)=([^&]*)/).inject({}){|h, v| h[v[0]] = v[1]; h}) 
    2323        raise "no postkey (#{content})" unless @params.key?('postkey') 
    2424 
     
    2828 
    2929        vpos = case time 
    30                when /(\d+):(\d+\.\d+|\d+)/ 
     30               when /(\d+):(\d+(?:\.\d+)?)/ 
    3131                 ($1.to_i * 6000) + ($2.to_f * 100).to_i 
    32                when /(\d+\.\d+|\d+)/ 
    33                  ($1.to_f * 100).to_i 
     32               when /\d+(?:\.\d+)?/ 
     33                 ($&.to_f * 100).to_i 
    3434               end 
    3535 
  • lang/ruby/nicovideo-post-ext/lib/nicovideo-wayback-ext.rb

    r15307 r19028  
    1313        @params = get_params unless @params 
    1414        thread_id = @params['thread_id'] 
    15         body = %!<thread res_from="-#{num}" version="20061206" thread="#{thread_id}" />! 
     15        body = %!<thread res_from="-#{num}" version="20061206" thread="#{thread_id}"/>! 
    1616 
    1717        if time 
     
    2424          @params.merge!(content.scan(/([^&]+)=([^&]*)/).inject({}){|h, v| h[v[0]] = v[1]; h}) 
    2525          raise ArgError, "no waybackkey: #{content}" unless @params.key?('waybackkey') 
    26           body.sub!(/( \/>)/, { 
     26          body.sub!(%r{(?=/>)}, { 
    2727            :user_id => @params['user_id'], 
    2828            :when => time.to_i, 
    2929            :waybackkey => @params['waybackkey'] 
    30           }.map{|k,v| %! #{k}="#{v}"!}.join + ' />') 
     30          }.map{|k,v| %! #{k}="#{v}"!}.join) 
    3131        end 
    3232