Class: Watchmob::Watchlist
- Inherits:
-
Object
- Object
- Watchmob::Watchlist
- Includes:
- ViewHelpers
- Defined in:
- lib/watchmob/watchlist.rb
Constant Summary collapse
- HAML_TEMPLATE =
File.("../watchlist.haml", __FILE__)
- PHONE_TIMEOUT =
15.0
Instance Attribute Summary collapse
-
#phones ⇒ Object
readonly
Returns the value of attribute phones.
Instance Method Summary collapse
-
#initialize(json) ⇒ Watchlist
constructor
A new instance of Watchlist.
- #sort_by!(property) ⇒ Object
- #to_html ⇒ Object
Methods included from ViewHelpers
#format_datetime, #format_time_interval
Constructor Details
#initialize(json) ⇒ Watchlist
Returns a new instance of Watchlist.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/watchmob/watchlist.rb', line 14 def initialize(json) @phones = [] phone_threads = json.map do |phone_json| params = if phone_json.is_a? Array {"aukro" => phone_json[0], "phone" => phone_json[1]} else phone_json end Thread.new do Thread.current.abort_on_exception = true @phones << Smartphone.find(params) end end Timeout.timeout(PHONE_TIMEOUT) do phone_threads.each(&:join) end end |
Instance Attribute Details
#phones ⇒ Object (readonly)
Returns the value of attribute phones.
35 36 37 |
# File 'lib/watchmob/watchlist.rb', line 35 def phones @phones end |
Instance Method Details
#sort_by!(property) ⇒ Object
37 38 39 40 |
# File 'lib/watchmob/watchlist.rb', line 37 def sort_by!(property) @phones.sort_by! { |phone| phone.aukro_page.uri.to_s } @phones.sort_by! { |phone| phone.__send__(property) or 0 } end |
#to_html ⇒ Object
42 43 44 45 |
# File 'lib/watchmob/watchlist.rb', line 42 def to_html engine = Haml::Engine.new(File.read(HAML_TEMPLATE), :filename => HAML_TEMPLATE) engine.render(self) end |