Class: FakerMaker::Attribute
- Inherits:
-
Object
- Object
- FakerMaker::Attribute
- Defined in:
- lib/faker_maker/attribute.rb
Overview
Attributes describe the fields of classes
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#translation ⇒ Object
readonly
Returns the value of attribute translation.
Instance Method Summary collapse
- #array? ⇒ Boolean
- #cardinality ⇒ Object
-
#initialize(name, block = nil, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #omit?(value) ⇒ Boolean
- #translation? ⇒ Boolean
Constructor Details
#initialize(name, block = nil, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
8 9 10 11 12 13 14 15 16 |
# File 'lib/faker_maker/attribute.rb', line 8 def initialize( name, block = nil, = {} ) @name = name @block = block || proc {} @cardinality = [:has] || 1 @translation = [:json] @omit = *[:omit] @array = [:array] == true end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def name @name end |
#translation ⇒ Object (readonly)
Returns the value of attribute translation.
6 7 8 |
# File 'lib/faker_maker/attribute.rb', line 6 def translation @translation end |
Instance Method Details
#array? ⇒ Boolean
18 19 20 |
# File 'lib/faker_maker/attribute.rb', line 18 def array? forced_array? || @array end |
#cardinality ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/faker_maker/attribute.rb', line 22 def cardinality if @cardinality.is_a? Range rand( @cardinality ) else @cardinality end end |
#omit?(value) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/faker_maker/attribute.rb', line 34 def omit?( value ) case value when nil @omit.include?( :nil ) || @omit.include?( nil ) when '', [], {} @omit.include? :empty else @omit.include?( :always ) || @omit.include?( value ) end end |
#translation? ⇒ Boolean
30 31 32 |
# File 'lib/faker_maker/attribute.rb', line 30 def translation? !@translation.blank? end |