Class: Topsy::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/rtopsy/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, content_type) ⇒ Page

creates a Page instance from a hash, setting attributes and a list of Author instances for the page



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rtopsy/page.rb', line 77

def initialize(hash, content_type)
  hash.each do |key, value|
    if key == 'list' 
      if content_type == :author
        instance_variable_set("@#{key}", get_authors_list(value))  
      elsif content_type == :link_post
        instance_variable_set("@#{key}", get_linkposts_list(value))
      elsif content_type == :tag
        instance_variable_set("@#{key}", get_tags_list(value))
      elsif content_type == :trend
        instance_variable_set("@#{key}", get_trends_list(value))
      elsif content_type == :tweet
        instance_variable_set("@#{key}", get_tweets_list(value))
      else
        instance_variable_set("@#{key}", get_linksearchresult_list(value))
      end
      
    else
      instance_variable_set("@#{key}", value)  
    end
  end
end

Instance Attribute Details

#listObject

Returns the value of attribute list.



15
16
17
# File 'lib/rtopsy/page.rb', line 15

def list
  @list
end

#pageObject

Returns the value of attribute page.



15
16
17
# File 'lib/rtopsy/page.rb', line 15

def page
  @page
end

#perpageObject

Returns the value of attribute perpage.



15
16
17
# File 'lib/rtopsy/page.rb', line 15

def perpage
  @perpage
end

#totalObject

Returns the value of attribute total.



15
16
17
# File 'lib/rtopsy/page.rb', line 15

def total
  @total
end

#windowObject

Returns the value of attribute window.



15
16
17
# File 'lib/rtopsy/page.rb', line 15

def window
  @window
end

Instance Method Details

#get_authors_list(hash_list) ⇒ Object

converts a list of Hash objects into Author objects



22
23
24
25
26
27
28
# File 'lib/rtopsy/page.rb', line 22

def get_authors_list(hash_list)
  result = []
  for hash in hash_list
    result << Author.new(hash)
  end
  return result
end

#get_linkposts_list(hash_list) ⇒ Object

converts a list of Hash objects into Linkpost objects



31
32
33
34
35
36
37
# File 'lib/rtopsy/page.rb', line 31

def get_linkposts_list(hash_list)
  result = []
  for hash in hash_list
    result << Linkpost.new(hash)
  end
  return result
end

#get_linksearchresult_list(hash_list) ⇒ Object

converts a list of Hash objects into LinkSearchResult objects



40
41
42
43
44
45
46
# File 'lib/rtopsy/page.rb', line 40

def get_linksearchresult_list(hash_list)
  result = []
  for hash in hash_list
    result << LinkSearchResult.new(hash)
  end
  return result
end

#get_tags_list(hash_list) ⇒ Object

converts a list of Hash objects into Tag objects



49
50
51
52
53
54
55
# File 'lib/rtopsy/page.rb', line 49

def get_tags_list(hash_list)
  result = []
  for hash in hash_list
    result << Tag.new(hash)
  end
  return result
end

converts a list of Hash objects into Trend objects



58
59
60
61
62
63
64
# File 'lib/rtopsy/page.rb', line 58

def get_trends_list(hash_list)
  result = []
  for hash in hash_list
    result << Trend.new(hash)
  end
  return result
end

#get_tweets_list(hash_list) ⇒ Object

converts a list of Hash objects into Tweet objects



67
68
69
70
71
72
73
# File 'lib/rtopsy/page.rb', line 67

def get_tweets_list(hash_list)
  result = []
  for hash in hash_list
    result << Tweet.new(hash)
  end
  return result
end

#to_sObject



17
18
19
# File 'lib/rtopsy/page.rb', line 17

def to_s
  "Topsy Page: #{page} of #{total}, #{list.size} authors"
end