Class: LocalRecord
- Inherits:
-
Struct
- Object
- Struct
- LocalRecord
- Defined in:
- lib/tworgy/local_record.rb
Constant Summary collapse
- @@all_children =
{}
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .all ⇒ Object
- .append_to_all(klass, record) ⇒ Object
- .find(*args) ⇒ Object
- .inherited(klass) ⇒ Object
- .pick_random ⇒ Object
- .selections ⇒ Object
Instance Method Summary collapse
- #<=>(b) ⇒ Object
- #destroyed? ⇒ Boolean
-
#initialize(id, name) ⇒ LocalRecord
constructor
A new instance of LocalRecord.
- #new_record? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(id, name) ⇒ LocalRecord
Returns a new instance of LocalRecord.
8 9 10 11 12 13 |
# File 'lib/tworgy/local_record.rb', line 8 def initialize(id, name) self.id = id self.name = name self.class.const_set(name.titleize.gsub(/ /, ''), self) LocalRecord.append_to_all(self.class, self) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id
1 2 3 |
# File 'lib/tworgy/local_record.rb', line 1 def id @id end |
#name ⇒ Object
Returns the value of attribute name
1 2 3 |
# File 'lib/tworgy/local_record.rb', line 1 def name @name end |
Class Method Details
.all ⇒ Object
15 16 17 |
# File 'lib/tworgy/local_record.rb', line 15 def self.all @@all_children[self] end |
.append_to_all(klass, record) ⇒ Object
19 20 21 |
# File 'lib/tworgy/local_record.rb', line 19 def self.append_to_all(klass, record) @@all_children[klass] << record end |
.find(*args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tworgy/local_record.rb', line 27 def self.find(*args) if args.length == 1 id = args[0] all.find { |c| c.id == id } elsif args.length == 2 if args[0].is_a?(Fixnum) find(args[0]) elsif args[0] == :all all else DBC.assert(false, "No code written to handle args => #{args.inspect}") end else DBC.assert(false, "No code written to handle args => #{args.inspect}") end end |
.inherited(klass) ⇒ Object
4 5 6 |
# File 'lib/tworgy/local_record.rb', line 4 def self.inherited(klass) @@all_children[klass] = [] end |
.pick_random ⇒ Object
44 45 46 |
# File 'lib/tworgy/local_record.rb', line 44 def self.pick_random all[rand(all.length)] end |
.selections ⇒ Object
23 24 25 |
# File 'lib/tworgy/local_record.rb', line 23 def self.selections all.collect {|c| [c.name, c.id]} end |
Instance Method Details
#<=>(b) ⇒ Object
52 53 54 |
# File 'lib/tworgy/local_record.rb', line 52 def <=>(b) self.name <=> b.name end |
#destroyed? ⇒ Boolean
60 61 62 |
# File 'lib/tworgy/local_record.rb', line 60 def destroyed? false end |
#new_record? ⇒ Boolean
56 57 58 |
# File 'lib/tworgy/local_record.rb', line 56 def new_record? false end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/tworgy/local_record.rb', line 48 def to_s name end |