Method: OpenC3::CSV#bool

Defined in:
lib/openc3/utilities/csv.rb

#bool(item, index = 0) ⇒ Boolean Also known as: boolean

Convenience method to access a value by key and convert it to a boolean. The csv value must be ‘TRUE’ or ‘FALSE’ (case doesn’t matter) and will be converted to Ruby true or false values.

Parameters:

  • item (String)

    Key to access the value

  • index (Integer) (defaults to: 0)

    Which value to return

Returns:

  • (Boolean)

    Single value converted to a boolean (true or false)



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/openc3/utilities/csv.rb', line 66

def bool(item, index = 0)
  raise "#{item} not found" unless keys.include?(item)

  if Range === index
    @hash[item][index].map do |x|
      case x.upcase
      when 'TRUE'
        true
      when 'FALSE'
        false
      else
        raise "#{item} value of #{x} not boolean. Must be 'TRUE' 'or 'FALSE'."
      end
    end
  else
    case @hash[item][index].upcase
    when 'TRUE'
      true
    when 'FALSE'
      false
    else
      raise "#{item} value of #{@hash[item][index]} not boolean. Must be 'TRUE' 'or 'FALSE'."
    end
  end
end