Class: DubbletrackRemote::Item

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/dubbletrack_remote/item.rb

Constant Summary collapse

TRACK =
"track"
TRAFFIC =
"traffic"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rawObject

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_typeObject



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

#keyObject



42
43
44
# File 'lib/dubbletrack_remote/item.rb', line 42

def key
  "#{played_at.utc.iso8601}-#{title}:#{artist_name}"
end

#played_at_with_delayObject



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_printObject



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]" : ""
  if track?
    line = "TRACK: #{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 = "TRAFFIC: #{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_typeObject



33
34
35
# File 'lib/dubbletrack_remote/item.rb', line 33

def set_item_type
  self.item_type = detect_item_type
end

#track?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


50
51
52
# File 'lib/dubbletrack_remote/item.rb', line 50

def traffic?
  title.present? && played_at.present? && !track?
end