Method: Collins::CLI::Formatter#format_states

Defined in:
lib/collins/cli/formatter.rb

#format_states(states, opts = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/collins/cli/formatter.rb', line 25

def format_states(states, opts = {})
  if states.length > 0
    opts = FORMATTING_DEFAULTS.merge(opts)
    # map the hashes into openstructs that will respond to #send(:name)
    ostructs = states.map do |s|
      OpenStruct.new({
        :status_name => s.status.name || 'Any',
        :status_id => s.status.id || 0, # assign 0 to "Any" status
        :status_description => s.status.description || 'Any status',
        :state_name => s.name,
        :state_label => s.label,
        :state_id => s.id,
        :description => s.description
      })
    end
    ostructs.sort_by! {|x| "#{x.status_id}#{x.state_id}"}
    display_as_table(ostructs, STATUS_STATE_COLUMNS, opts[:separator], opts[:show_header])
  else
    raise "No states found"
  end
end