Class: Bmg::Operator::Generator
- Inherits:
-
Object
- Object
- Bmg::Operator::Generator
- Includes:
- Zeroary
- Defined in:
- lib/bmg/operator/generator.rb
Overview
Generator operator.
Generates a relation. Most inspired by PostgreSQL’s generate_series.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :as => :i, :step => 1, }
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, from, to, options = {}) ⇒ Generator
constructor
A new instance of Generator.
Methods included from Zeroary
Methods included from Bmg::Operator
Methods included from Relation
#_count, #bind, #count, #debug, #delete, #empty?, #insert, new, #one, #one_or_nil, #to_ast, #to_csv, #to_json, #to_text, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x
Methods included from Factory
#csv, #empty, #excel, #excel_file, #generate, #in_memory, #json, #json_file, #mutable, #text_file, #yaml, #yaml_file
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #undress, #ungroup, #union, #unspied, #unwrap
Methods included from Algebra::Shortcuts
#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where
Constructor Details
#initialize(type, from, to, options = {}) ⇒ Generator
Returns a new instance of Generator.
16 17 18 19 20 21 22 23 |
# File 'lib/bmg/operator/generator.rb', line 16 def initialize(type, from, to, = {}) = { step: } unless .is_a?(Hash) @type = type @from = from @to = to = DEFAULT_OPTIONS.merge() raise ArgumentError, "from, to and step must be defined" if from.nil? || to.nil? || step.nil? end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
24 25 26 |
# File 'lib/bmg/operator/generator.rb', line 24 def from @from end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/bmg/operator/generator.rb', line 24 def end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
24 25 26 |
# File 'lib/bmg/operator/generator.rb', line 24 def to @to end |
Instance Method Details
#each ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bmg/operator/generator.rb', line 26 def each return to_enum unless block_given? current = from as = [:as] until overflowed?(current) yield({ as => current }) current = next_of(current) end end |