Class: RedGrape::PropertyDescription
- Defined in:
- lib/red_grape/property_description.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #accessible?(val) ⇒ Boolean
- #convert(val) ⇒ Object
- #convertable?(val) ⇒ Boolean
- #has_default? ⇒ Boolean
-
#initialize(name, type, default = nil) ⇒ PropertyDescription
constructor
A new instance of PropertyDescription.
- #to_s ⇒ Object
Constructor Details
#initialize(name, type, default = nil) ⇒ PropertyDescription
Returns a new instance of PropertyDescription.
5 6 7 8 9 |
# File 'lib/red_grape/property_description.rb', line 5 def initialize(name, type, default=nil) @name = name @type = type @default = default end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
3 4 5 |
# File 'lib/red_grape/property_description.rb', line 3 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/red_grape/property_description.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/red_grape/property_description.rb', line 3 def type @type end |
Instance Method Details
#accessible?(val) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/red_grape/property_description.rb', line 11 def accessible?(val) case type when 'int', 'integer' val.is_a? Integer when 'float' val.is_a? Numeric else true end end |
#convert(val) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/red_grape/property_description.rb', line 33 def convert(val) case type when 'int', 'integer' val.to_i when 'float' val.to_f else val end end |
#convertable?(val) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/red_grape/property_description.rb', line 22 def convertable?(val) case type when 'int', 'integer' val =~ /^\d+$/ when 'float' val =~ /^\d+(\.\d+)?$/ else true end end |
#has_default? ⇒ Boolean
44 45 46 |
# File 'lib/red_grape/property_description.rb', line 44 def has_default? not @default.nil? end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/red_grape/property_description.rb', line 48 def to_s "{#{@name}:#{@type}:#{@default}}" end |