Class: UltimateLyrics::Provider
- Inherits:
-
Object
- Object
- UltimateLyrics::Provider
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
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
|
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
|
25
26
27
|
# File 'lib/ultimate_lyrics/provider.rb', line 25
def by_identifier(identifier)
by_attribute('identifier', identifier)
end
|
20
21
22
|
# File 'lib/ultimate_lyrics/provider.rb', line 20
def by_name(name)
by_attribute('name', name)
end
|
Instance Method Details
#encoding ⇒ Object
39
40
41
|
# File 'lib/ultimate_lyrics/provider.rb', line 39
def encoding
node.attribute('charset').text
end
|
#exclude_rules ⇒ Object
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
|
43
44
45
46
47
|
# File 'lib/ultimate_lyrics/provider.rb', line 43
def
node.xpath('./extract').map do |v|
::UltimateLyrics::Provider::Rule.new(v)
end
end
|
#identifier ⇒ Object
55
56
57
|
# File 'lib/ultimate_lyrics/provider.rb', line 55
def identifier
name.variableize
end
|
#invalid_indicators ⇒ Object
59
60
61
|
# File 'lib/ultimate_lyrics/provider.rb', line 59
def invalid_indicators
node.xpath('/invalidIndicator/@value').map(&:text)
end
|
#name ⇒ String
64
65
66
|
# File 'lib/ultimate_lyrics/provider.rb', line 64
def name
node.attribute('name').text
end
|
#rules ⇒ Object
68
69
70
|
# File 'lib/ultimate_lyrics/provider.rb', line 68
def rules
+ exclude_rules
end
|
#title ⇒ Object
88
89
90
|
# File 'lib/ultimate_lyrics/provider.rb', line 88
def title
node.attribute('text').text
end
|
#to_s ⇒ Object
92
93
94
|
# File 'lib/ultimate_lyrics/provider.rb', line 92
def to_s
name
end
|
#url ⇒ String
73
74
75
|
# File 'lib/ultimate_lyrics/provider.rb', line 73
def url
node.attribute('url').text
end
|
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
|