class MediaInfo::Tracks::Attributes

Public Class Methods

new(params) click to toggle source
   # File lib/mediainfo/tracks.rb
81 def initialize(params)
82   params.each{ |param|
83     if param[1].is_a?(Array)
84       MediaInfo.set_singleton_method(self,param[0],Extra.new(param[1]))
85     else
86       MediaInfo.set_singleton_method(self,param[0],MediaInfo::Tracks::Attributes.sanitize_element_value(param))
87     end
88   }
89 end
sanitize_element_value(param) click to toggle source
    # File lib/mediainfo/tracks.rb
 97 def self.sanitize_element_value(param)
 98   name = param[0]
 99   value = param[1]
100 
101   if ['Duration'].include?(name)
102     # Duration
103     return standardize_to_milliseconds(value)
104   elsif value.to_s == value.to_i.to_s then value.to_i
105     # Convert String with integer in it to Integer.
106     return value.to_i
107   elsif value.to_s == value.to_f.to_s then value.to_f
108     # Convert String with integer in it to Integer.
109     return value.to_f
110   elsif name.downcase.include?('date') && !value.match(/\d-/).nil?
111     # Dates
112     return Time.parse(value.sub(/^UTC\s+(.*)$/, '\1 UTC'))
113   end
114 
115   value
116 end
standardize_float_to_milliseconds(v) click to toggle source
    # File lib/mediainfo/tracks.rb
138 def self.standardize_float_to_milliseconds(v)
139   (v*1000).to_i
140 end
standardize_string_to_milliseconds(v, base_msec = 0) click to toggle source
    # File lib/mediainfo/tracks.rb
124 def self.standardize_string_to_milliseconds(v, base_msec = 0)
125   v.scan(/\d+\s?\D+/).each do |chunk|
126     base_msec += case chunk
127     when /\d+\s?ms/         then chunk.to_i
128     when /\d+\s?s(ec)?/     then chunk.to_i * 1000
129     when /\d+\s?m(i?n)?/    then chunk.to_i * 60 * 1000
130     when /\d+\s?h(our)?/    then chunk.to_i * 60 * 60 * 1000
131     end.to_i
132   end
133   # We don't raise anymore. It's much better for the gem to
134   # return the original MediaInfo attribute, than raise.
135   base_msec == 0 ? v : base_msec
136 end
standardize_to_milliseconds(value) click to toggle source
    # File lib/mediainfo/tracks.rb
118 def self.standardize_to_milliseconds(value)
119   return standardize_float_to_milliseconds(value.to_f) if value =~ /^\d+\.?\d*$/
120   return standardize_string_to_milliseconds(value)
121   value
122 end

Public Instance Methods

method_missing( name, *args ) click to toggle source

Needed so that sanitize_elements doesn't throw NoMethodError

   # File lib/mediainfo/tracks.rb
77 def method_missing( name, *args )
78   nil # We use nil here instead of false as nil should be understood by the client/requester as false. We might not want to specifically return false for other missing methods
79 end