Class: FLACsmith::Metadata::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/flacsmith/metadata/tag.rb

Overview

Represents metadata tag information.

Constant Summary collapse

KEYS =
%w[
  ALBUM
  ARTIST
  CONTACT
  COPYRIGHT
  DATE
  DESCRIPTION
  GENRE
  ISRC
  LICENSE
  LOCATION
  ORGANIZATION
  PERFORMER
  TITLE
  TRACKNUMBER
  VERSION
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, initial_value = "") ⇒ Tag

Returns a new instance of Tag.



37
38
39
40
41
# File 'lib/flacsmith/metadata/tag.rb', line 37

def initialize key, initial_value = ""
  @key = key
  @initial_value = String initial_value
  validate
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



27
28
29
# File 'lib/flacsmith/metadata/tag.rb', line 27

def key
  @key
end

Class Method Details

.defaultsObject



29
30
31
# File 'lib/flacsmith/metadata/tag.rb', line 29

def self.defaults
  KEYS.map { |key| self.for key }
end

.for(key, value = "") ⇒ Object



33
34
35
# File 'lib/flacsmith/metadata/tag.rb', line 33

def self.for key, value = ""
  new key, value
end

Instance Method Details

#to_sObject Also known as: to_str



49
50
51
# File 'lib/flacsmith/metadata/tag.rb', line 49

def to_s
  "#{key}=#{value}"
end

#valueObject



43
44
45
46
47
# File 'lib/flacsmith/metadata/tag.rb', line 43

def value
  return initial_value if initial_value.empty?

  Shellwords.escape initial_value
end