Class: Potter::Types::Type

Inherits:
Object
  • Object
show all
Includes:
OptionHelpers
Defined in:
lib/potter/types.rb

Direct Known Subclasses

Boolean, Date, DateTime, Decimal, Float, Integer, String, Time

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionHelpers

#assign_option!, #assign_options!

Constructor Details

#initializeType

Returns a new instance of Type.



14
15
16
# File 'lib/potter/types.rb', line 14

def initialize(**)
  assign_options!(**)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/potter/types.rb', line 12

def options
  @options
end

Instance Method Details

#from(o) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/potter/types.rb', line 22

def from(o)
  case o
  when klass  then o
  when String then parse(o)
  else new(o)
  end
end

#generate(o) ⇒ Object



32
# File 'lib/potter/types.rb', line 32

def generate(o) = o.to_s

#klassObject



19
# File 'lib/potter/types.rb', line 19

def klass  = Object.const_get(name)

#nameObject



18
# File 'lib/potter/types.rb', line 18

def name   = self.class.name.split('::').last

#new(o) ⇒ Object



30
# File 'lib/potter/types.rb', line 30

def new(o)      = klass.new(o)

#parse(o) ⇒ Object



31
# File 'lib/potter/types.rb', line 31

def parse(o)    = klass.parse(o)

#to_symObject



20
# File 'lib/potter/types.rb', line 20

def to_sym = name.underscore.to_sym