Class: PositionalGenerator::Builder
- Inherits:
-
Object
- Object
- PositionalGenerator::Builder
- Defined in:
- lib/helpers/positional_generator.rb
Defined Under Namespace
Classes: Computed, Group, Int, Letter, Literal, Oneof
Instance Attribute Summary collapse
-
#as_type ⇒ Object
readonly
Returns the value of attribute as_type.
Instance Method Summary collapse
-
#build ⇒ String
Generate the value.
-
#computed(name: nil, deps: [], &block) ⇒ void
Fill the position with an arbitrary value.
-
#group(name: nil, &block) ⇒ void
A group of generators.
-
#initialize(as_type) ⇒ Builder
constructor
A new instance of Builder.
-
#int(name: nil, length: 1, ranges: nil) ⇒ void
Generate a value in the range of 0..9.
-
#letter(name: nil, length: 1, ranges: ['a'..'z', 'A'..'Z']) ⇒ void
Generate a value in the range of ‘a’..‘Z’.
-
#lit(value, name: nil) ⇒ void
Generate a literal String.
-
#oneof(name: nil, &block) ⇒ void
Fill the position with one of the results from the given generators.
Constructor Details
#initialize(as_type) ⇒ Builder
Returns a new instance of Builder.
37 38 39 40 |
# File 'lib/helpers/positional_generator.rb', line 37 def initialize(as_type) @components = [] @as_type = as_type end |
Instance Attribute Details
#as_type ⇒ Object (readonly)
Returns the value of attribute as_type.
35 36 37 |
# File 'lib/helpers/positional_generator.rb', line 35 def as_type @as_type end |
Instance Method Details
#build ⇒ String
Generate the value.
161 162 163 164 165 166 |
# File 'lib/helpers/positional_generator.rb', line 161 def build graph = build_graph stack = build_stack(graph) values = generate_values(stack) convert(values) end |
#computed(name: nil, deps: [], &block) ⇒ void
This method returns an undefined value.
Fill the position with an arbitrary value.
117 118 119 |
# File 'lib/helpers/positional_generator.rb', line 117 def computed(name: nil, deps: [], &block) @components << Component.new(@components.count, name, deps, Computed.new(block)) end |
#group(name: nil, &block) ⇒ void
This method returns an undefined value.
A group of generators. Useful for #oneof.
153 154 155 |
# File 'lib/helpers/positional_generator.rb', line 153 def group(name: nil, &block) @components << Component.new(@components.count, name, [], Group.new(@as_type, block)) end |
#int(name: nil, length: 1, ranges: nil) ⇒ void
This method returns an undefined value.
Generate a value in the range of 0..9.
60 61 62 |
# File 'lib/helpers/positional_generator.rb', line 60 def int(name: nil, length: 1, ranges: nil) @components << Component.new(@components.count, name, [], Int.new(length, ranges)) end |
#letter(name: nil, length: 1, ranges: ['a'..'z', 'A'..'Z']) ⇒ void
This method returns an undefined value.
Generate a value in the range of ‘a’..‘Z’.
82 83 84 |
# File 'lib/helpers/positional_generator.rb', line 82 def letter(name: nil, length: 1, ranges: ['a'..'z', 'A'..'Z']) @components << Component.new(@components.count, name, [], Letter.new(length, ranges)) end |
#lit(value, name: nil) ⇒ void
This method returns an undefined value.
Generate a literal String
94 95 96 |
# File 'lib/helpers/positional_generator.rb', line 94 def lit(value, name: nil) @components << Component.new(@components.count, name, [], Literal.new(value)) end |
#oneof(name: nil, &block) ⇒ void
This method returns an undefined value.
Fill the position with one of the results from the given generators.
143 144 145 |
# File 'lib/helpers/positional_generator.rb', line 143 def oneof(name: nil, &block) @components << Component.new(@components.count, name, [], Oneof.new(self, block)) end |