Class: LocalRecord

Inherits:
Struct
  • Object
show all
Defined in:
lib/tworgy/local_record.rb

Constant Summary collapse

@@all_children =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



1
2
3
# File 'lib/tworgy/local_record.rb', line 1

def id
  @id
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



1
2
3
# File 'lib/tworgy/local_record.rb', line 1

def name
  @name
end

Class Method Details

.allObject



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_randomObject



44
45
46
# File 'lib/tworgy/local_record.rb', line 44

def self.pick_random
  all[rand(all.length)]
end

.selectionsObject



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

Returns:

  • (Boolean)


60
61
62
# File 'lib/tworgy/local_record.rb', line 60

def destroyed?
  false
end

#new_record?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/tworgy/local_record.rb', line 56

def new_record?
  false
end

#to_sObject



48
49
50
# File 'lib/tworgy/local_record.rb', line 48

def to_s
  name
end