Class: Idiomag::Tag
- Inherits:
-
Object
show all
- Defined in:
- lib/idiomag/tag.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(tag) ⇒ Tag
Returns a new instance of Tag.
3
4
5
6
|
# File 'lib/idiomag/tag.rb', line 3
def initialize(tag)
raise ArgumentError if tag.blank?
@tag = tag.to_s.gsub(/_/, ' ')
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/idiomag/tag.rb', line 36
def method_missing(method, *args)
case method
when :name
@tag
when :articles
get_articles if @articles.nil?
@articles
when :photos
get_photos if @photos.nil?
@photos
when :videos
get_videos if @videos.nil?
@videos
when :playlist, :tracks
get_playlist if @playlist.nil?
@playlist
when :artists
get_artists if @artists.nil?
@artists
when :list
Tag.list
else
super
end
end
|
Class Method Details
.list ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/idiomag/tag.rb', line 63
def list
if @list.blank?
@list_data = REST.fetch('tags', {}, false)
@list = @list_data.split("\n")
@list.map! do |t|
if t =~ /-/
t.strip.downcase
else
t.strip.downcase.gsub(/ /, '_').to_sym
end
end
else
@list
end
end
|
Instance Method Details
#get(*args) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/idiomag/tag.rb', line 8
def get(*args)
args.each do |action|
case action
when :articles
get_articles
when :photos
get_photos
when :videos
get_videos
when :playlist, :tracks
get_playlist
when :artists
get_artists
else
raise ArgumentError
end
end
end
|
#respond_to?(method) ⇒ Boolean
27
28
29
30
31
32
33
34
|
# File 'lib/idiomag/tag.rb', line 27
def respond_to?(method)
case method
when :articles,:photos,:videos,:playlist,:tracks,:artists,:list,:name
true
else
super
end
end
|