Class: DubbletrackRemote::Item
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DubbletrackRemote::Item
- Defined in:
- lib/dubbletrack_remote/item.rb
Constant Summary collapse
- TRACK =
"track"
- TRAFFIC =
"traffic"
Instance Attribute Summary collapse
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
- #detect_item_type ⇒ Object
- #key ⇒ Object
- #played_at_with_delay ⇒ Object
- #pretty_print ⇒ Object
- #set_item_type ⇒ Object
- #track? ⇒ Boolean
- #traffic? ⇒ Boolean
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
25 26 27 |
# File 'lib/dubbletrack_remote/item.rb', line 25 def raw @raw end |
Instance Method Details
#detect_item_type ⇒ Object
37 38 39 40 |
# File 'lib/dubbletrack_remote/item.rb', line 37 def detect_item_type return TRACK if track? return TRAFFIC if traffic? end |
#key ⇒ Object
42 43 44 |
# File 'lib/dubbletrack_remote/item.rb', line 42 def key "#{played_at.utc.iso8601}-#{title}:#{artist_name}" end |
#played_at_with_delay ⇒ Object
27 28 29 30 31 |
# File 'lib/dubbletrack_remote/item.rb', line 27 def played_at_with_delay played_at + (Settings&.automation&.delay_seconds || 0).seconds rescue played_at end |
#pretty_print ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dubbletrack_remote/item.rb', line 54 def pretty_print state = if success "[✓] " elsif last_error_code "[×] " else "[ ] " end duration_s = duration ? " [#{duration}s]" : "[DURATION MISSING]" if track? line = "#{state}#{id}:#{played_at.utc.iso8601}".ljust(30) + " " + "#{title} - #{artist_name}" "\r\n" + " ".ljust(32) + "#{release_name} // #{label_name} \r\n" + " ".ljust(32) + "#{genre}, #{duration_s}, #{automation_group}, #{automation_id}" + "\r\n" + (last_error_code ? "".ljust(30) + "[#{last_error_code}] #{last_error_text}" : "") + "\r\n" elsif traffic? line = "#{state}#{id}:#{played_at.utc.iso8601}".ljust(30) + " " + title.to_s + "\r\n" + "#{genre}, #{duration_s}, #{automation_group}, #{automation_id}" + "\r\n" + (last_error_code ? "".ljust(30) + "[#{last_error_code}] #{last_error_text}" : "") + "\r\n" else line = "UNKNOWN: #{state}#{id}:#{played_at.utc.iso8601}".ljust(30) + title.to_s + "\r\n" + "#{genre}, #{duration_s}, #{automation_group}, #{automation_id}" + "\r\n" + (last_error_code ? "".ljust(30) + "[#{last_error_code}] #{last_error_text}" : "") + "\r\n" end end |
#set_item_type ⇒ Object
33 34 35 |
# File 'lib/dubbletrack_remote/item.rb', line 33 def set_item_type self.item_type = detect_item_type end |
#track? ⇒ Boolean
46 47 48 |
# File 'lib/dubbletrack_remote/item.rb', line 46 def track? title.present? && played_at.present? && artist_name.present? && (label_name.present? || release_name.present?) # label name and release name could technically be left out, even though they shouldn't end |
#traffic? ⇒ Boolean
50 51 52 |
# File 'lib/dubbletrack_remote/item.rb', line 50 def traffic? title.present? && played_at.present? && !track? end |