Module: EasyTag::BaseAttributeAccessors

Included in:
MP3AttributeAccessors, MP4AttributeAccessors, VorbisAttributeAccessors
Defined in:
lib/easytag/attributes/base.rb

Instance Method Summary collapse

Instance Method Details

#audio_prop_reader(attr_name, prop_name = nil, **opts) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/easytag/attributes/base.rb', line 4

def audio_prop_reader(attr_name, prop_name = nil, **opts)
  prop_name = attr_name if prop_name.nil?
  define_method(attr_name) do
    v = self.class.read_audio_property(taglib, prop_name)
    self.class.post_process(v, opts)
  end
end

#cast(data, key, **opts) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/easytag/attributes/base.rb', line 12

def cast(data, key, **opts)
  case opts[key]
  when :int
    data.to_i
  when :int_pair
    Utilities.get_int_pair(data)
  when :datetime
    Utilities.get_datetime(data.to_s)
  when :list
    Array(data)
  when :bool
    [1, '1', true].include?(data)
  else
    data
  end
end

#extract(data, **opts) ⇒ Object



29
30
31
32
33
34
# File 'lib/easytag/attributes/base.rb', line 29

def extract(data, **opts)
  if opts.has_key?(:extract_list_pos)
    data = data[opts[:extract_list_pos]]
  end
  data
end

#post_process(data, opts) ⇒ Object



36
37
38
39
40
# File 'lib/easytag/attributes/base.rb', line 36

def post_process(data, opts)
  data = cast(data, :cast, **opts)
  data = extract(data, **opts)
  cast(data, :returns, **opts)
end

#read_audio_property(taglib, key) ⇒ Object



42
43
44
# File 'lib/easytag/attributes/base.rb', line 42

def read_audio_property(taglib, key)
  taglib.audio_properties.send(key)
end