lib/mediainfo/attr_readers.rb in mediainfo-0.5.1 vs lib/mediainfo/attr_readers.rb in mediainfo-0.6.0
- old
+ new
@@ -1,28 +1,30 @@
-require "rubygems"
-require "active_support" # TODO selective includes once they are released
+require "time"
+require "mediainfo/string"
class Mediainfo
module AttrReaders
def supported_attributes
@supported_attributes ||= []
end
def mediainfo_attr_reader(name, mediainfo_key = nil)
supported_attributes << name
attr_name = "#{name}_before_type_cast"
+ mediainfo_key = mediainfo_key.gsub(/\W+/, "_").downcase if mediainfo_key
+
define_method attr_name do
if v = instance_variable_get("@#{attr_name}")
v
else
v = if md = name.to_s.match(/^(#{SECTIONS.map { |x| x.underscore } * "|"})_(.+)$/)
- k = mediainfo_key ? mediainfo_key : md[2].humanize.capitalize
- if subsection = @parsed_response[md[1].capitalize]
+ k = mediainfo_key ? mediainfo_key : md[2]
+ if subsection = @parsed_response[md[1]]
subsection[k]
end
else
- k = mediainfo_key ? mediainfo_key : name.to_s.humanize.capitalize
+ k = mediainfo_key ? mediainfo_key : name.to_s
@parsed_response[k]
end
instance_variable_set "@#{attr_name}", v
v
@@ -68,9 +70,9 @@
def mediainfo_int_reader(*a)
mediainfo_attr_reader(*a) { |v| v.gsub(/\D+/, "").to_i }
end
def mediainfo_section_query(name)
- define_method("#{name}?") { @parsed_response.key? name.to_s.capitalize }
+ define_method("#{name}?") { @parsed_response.key? name.to_s }
end
end
end