Class: ConlangWordGenerator::Maybe

Inherits:
Object
  • Object
show all
Defined in:
lib/conlang/operators.rb

Instance Method Summary collapse

Constructor Details

#initialize(weight, set) ⇒ Maybe

Returns a new instance of Maybe.



67
68
69
70
71
72
73
74
75
# File 'lib/conlang/operators.rb', line 67

def initialize(weight, set)
  unless weight > 0 and weight < 100
    raise LangSyntaxError, "Weight for an maybe() operator " +
                           "must be between 1 and 100 (exclusive)."
  end

  @weight = weight
  @set = set
end

Instance Method Details

#+(other) ⇒ Object



85
86
87
# File 'lib/conlang/operators.rb', line 85

def +(other)
  Append.new(self, other)
end

#sampleObject



77
78
79
80
81
82
83
# File 'lib/conlang/operators.rb', line 77

def sample
  if rand(100) < @weight
    @set.sample
  else
    ""
  end
end