class Protip::Transformers::PrimitivesTransformer

Transforms ints, strings, booleans, floats, and bytes to/from their well-known types (for scalars) and Protip repeated types.

Constants

FALSE_VALUES
TRUE_VALUES

Public Class Methods

new() click to toggle source
# File lib/protip/transformers/primitives_transformer.rb, line 13
def initialize
  super
  {
    Int64:   :to_i.to_proc,
    Int32:   :to_i.to_proc,
    UInt64:  :to_i.to_proc,
    UInt32:  :to_i.to_proc,
    Double:  :to_f.to_proc,
    Float:   :to_f.to_proc,
    String:  :to_s.to_proc,
    Bool:    ->(object) { to_boolean(object) },
    Bytes:   ->(object) { object },
  }.each do |type, transform|
    self["google.protobuf.#{type}Value"] = ScalarTransformer.new(transform)
    self["protip.messages.Repeated#{type}"] = ArrayTransformer.new(transform)
  end          
end

Private Instance Methods

to_boolean(object) click to toggle source
# File lib/protip/transformers/primitives_transformer.rb, line 32
def to_boolean(object)
  return true if TRUE_VALUES.include?(object)
  return false if FALSE_VALUES.include?(object)

  object
end