Class: List
- Inherits:
-
Object
- Object
- List
- Defined in:
- lib/dunmanifestin/list.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #<<(rough_member) ⇒ Object
-
#initialize(opts = {}) ⇒ List
constructor
A new instance of List.
- #sample ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ List
Returns a new instance of List.
4 5 6 7 8 9 10 |
# File 'lib/dunmanifestin/list.rb', line 4 def initialize opts={} @name = opts.fetch(:name, 'default') @members = opts.fetch(:members, []) @universe = opts.fetch(:universe) @universe.lists[name] = self puts members end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/dunmanifestin/list.rb', line 2 def name @name end |
Instance Method Details
#<<(rough_member) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dunmanifestin/list.rb', line 13 def << rough_member pieces = rough_member.split('@') weight = pieces.length > 1 ? pieces.shift.to_i : 1 attrs = {body: pieces.pop, list: self, universe: universe} attrs.merge!(frequency: pieces.pop) if pieces.any? member = Member.new(attrs) weight.times { members << member } end |
#sample ⇒ Object
25 26 27 |
# File 'lib/dunmanifestin/list.rb', line 25 def sample members.sample end |