Class: UltimateLyrics::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/ultimate_lyrics/provider.rb,
lib/ultimate_lyrics/provider/item.rb,
lib/ultimate_lyrics/provider/rule.rb,
lib/ultimate_lyrics/provider/url_format.rb,
lib/ultimate_lyrics/provider/exclude_item.rb,
lib/ultimate_lyrics/provider/extract_item.rb,
lib/ultimate_lyrics/provider/replace_fields.rb

Defined Under Namespace

Classes: ExcludeItem, ExtractItem, Item, ReplaceFields, Rule, UrlFormat

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allArray<UltimateLyrics::Provider>

Returns:



13
14
15
16
17
# File 'lib/ultimate_lyrics/provider.rb', line 13

def all
  @all ||= ::Nokogiri::XML(
    ::File.new(::File.join(__dir__, 'providers_data.xml'))
  ).xpath('/lyricproviders/provider').map { |node| new(node) }
end

.by_attribute(attribute, value) ⇒ UltimateLyrics::Provider



30
31
32
33
34
# File 'lib/ultimate_lyrics/provider.rb', line 30

def by_attribute(attribute, value)
  all.find { |provider| provider.send(attribute) == value } ||
    raise("No provider with name \"#{value}\" (Available: " +
      all.map { |p| p.send(attrbute) }.join(', ') + ')')
end

.by_identifier(identifier) ⇒ UltimateLyrics::Provider



25
26
27
# File 'lib/ultimate_lyrics/provider.rb', line 25

def by_identifier(identifier)
  by_attribute('identifier', identifier)
end

.by_name(name) ⇒ UltimateLyrics::Provider



20
21
22
# File 'lib/ultimate_lyrics/provider.rb', line 20

def by_name(name)
  by_attribute('name', name)
end

Instance Method Details

#encodingObject



39
40
41
# File 'lib/ultimate_lyrics/provider.rb', line 39

def encoding
  node.attribute('charset').text
end

#exclude_rulesObject



49
50
51
52
53
# File 'lib/ultimate_lyrics/provider.rb', line 49

def exclude_rules
  node.xpath('./exclude').map do |v|
    ::UltimateLyrics::Provider::Rule.new(v)
  end
end

#extract_rulesObject



43
44
45
46
47
# File 'lib/ultimate_lyrics/provider.rb', line 43

def extract_rules
  node.xpath('./extract').map do |v|
    ::UltimateLyrics::Provider::Rule.new(v)
  end
end

#identifierObject



55
56
57
# File 'lib/ultimate_lyrics/provider.rb', line 55

def identifier
  name.variableize
end

#invalid_indicatorsObject



59
60
61
# File 'lib/ultimate_lyrics/provider.rb', line 59

def invalid_indicators
  node.xpath('/invalidIndicator/@value').map(&:text)
end

#nameString

Returns:

  • (String)


64
65
66
# File 'lib/ultimate_lyrics/provider.rb', line 64

def name
  node.attribute('name').text
end

#rulesObject



68
69
70
# File 'lib/ultimate_lyrics/provider.rb', line 68

def rules
  extract_rules + exclude_rules
end

#titleObject



88
89
90
# File 'lib/ultimate_lyrics/provider.rb', line 88

def title
  node.attribute('text').text
end

#to_sObject



92
93
94
# File 'lib/ultimate_lyrics/provider.rb', line 92

def to_s
  name
end

#urlString

Returns:

  • (String)


73
74
75
# File 'lib/ultimate_lyrics/provider.rb', line 73

def url
  node.attribute('url').text
end

#url_fieldsArray<UltimateLyrics::Field>

Returns:



78
79
80
# File 'lib/ultimate_lyrics/provider.rb', line 78

def url_fields
  ::UltimateLyrics::Field.from_string(url)
end

#url_formatsObject



82
83
84
85
86
# File 'lib/ultimate_lyrics/provider.rb', line 82

def url_formats
  node.xpath('./urlFormat').map do |v|
    ::UltimateLyrics::Provider::UrlFormat.new(v)
  end
end