Method: OpenGraphReader::Object::DSL#boolean

Defined in:
lib/open_graph_reader/object/dsl/types.rb

#boolean(name, options = {}) ⇒ Object

Options Hash (options):

  • :required (Bool) — default: false

    Make the property required.

  • :collection (Bool) — default: false

    This property can occur multiple times.

  • :to (Class)

    This property maps to the given object (optional). belongs to the given verticals of the object (optional).

  • :verticials (Array<String>)

    This property

  • :downcase (Bool) — default: false

    Normalize the contents case to lowercase.



94
95
96
97
98
99
100
101
# File 'lib/open_graph_reader/object/dsl/types.rb', line 94

define_type :boolean do |value, options|
  {"true" => true, "false" => false, "1" => true, "0" => false}[value].tap {|bool|
    if bool.nil?
      next unless options[:required] || !OpenGraphReader.config.discard_invalid_optional_properties
      raise InvalidObjectError, "Boolean expected, but was #{value.inspect}"
    end
  }
end