Class: StarEthernet::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/star_ethernet/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(printer) ⇒ Status

Returns a new instance of Status.



7
8
9
10
# File 'lib/star_ethernet/status.rb', line 7

def initialize(printer)
  @printer = printer
  @status_items = []
end

Instance Attribute Details

#status_itemsObject (readonly)

Returns the value of attribute status_items.



5
6
7
# File 'lib/star_ethernet/status.rb', line 5

def status_items
  @status_items
end

Instance Method Details

#current_statusObject



12
13
14
# File 'lib/star_ethernet/status.rb', line 12

def current_status
  @status_items.last
end

#etb_incremented?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/star_ethernet/status.rb', line 20

def etb_incremented?
  return false if previous_status.nil?
  if previous_status.etb == 31 # ETB overflow
    current_status.etb == 0
  else
    current_status.etb == previous_status.etb + 1
  end
end

#full_messagesObject



35
36
37
38
39
40
# File 'lib/star_ethernet/status.rb', line 35

def full_messages
  <<~"EOS"
  #{@printer.host} printer's statuses are
  #{@status_items.map{ |status_item| status_item.message }.join("\n")}
  EOS
end

#previous_statusObject



16
17
18
# File 'lib/star_ethernet/status.rb', line 16

def previous_status
  @status_items[-2]
end

#set_status(status_data, purpose = '') ⇒ Object



29
30
31
32
33
# File 'lib/star_ethernet/status.rb', line 29

def set_status(status_data, purpose = '')
  current_status = StatusItem.decode_status(status_data)
  current_status.purpose = purpose
  @status_items.push(current_status)
end