Class: Dunlop::Generators::GeneratorHelpers::DunlopGeneratorAttribute
- Inherits:
-
Object
- Object
- Dunlop::Generators::GeneratorHelpers::DunlopGeneratorAttribute
- Defined in:
- lib/dunlop/generators/generator_helpers.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #boolean? ⇒ Boolean
- #column_name ⇒ Object
- #date? ⇒ Boolean
- #float? ⇒ Boolean
- #form_type ⇒ Object
-
#initialize(spec) ⇒ DunlopGeneratorAttribute
constructor
A new instance of DunlopGeneratorAttribute.
- #integer? ⇒ Boolean
- #numeric? ⇒ Boolean
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(spec) ⇒ DunlopGeneratorAttribute
Returns a new instance of DunlopGeneratorAttribute.
18 19 20 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 18 def initialize(spec) @name, @type = spec.to_s.strip.split(':') end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 17 def name @name end |
Instance Method Details
#boolean? ⇒ Boolean
41 42 43 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 41 def boolean? type == 'boolean' end |
#column_name ⇒ Object
26 27 28 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 26 def column_name name.to_s.underscore.gsub(/\W/, '_') end |
#date? ⇒ Boolean
57 58 59 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 57 def date? type == 'date' end |
#float? ⇒ Boolean
49 50 51 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 49 def float? %w[decimal float].include?(type) end |
#form_type ⇒ Object
34 35 36 37 38 39 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 34 def form_type case type when 'boolean' then 'boolean' else 'input' end end |
#integer? ⇒ Boolean
45 46 47 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 45 def integer? type == 'integer' end |
#numeric? ⇒ Boolean
53 54 55 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 53 def numeric? integer? or float? end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 30 def to_s name end |
#type ⇒ Object
22 23 24 |
# File 'lib/dunlop/generators/generator_helpers.rb', line 22 def type @type || 'string' end |