Class: Unitwise::Standard::Base
- Inherits:
-
Object
- Object
- Unitwise::Standard::Base
show all
- Includes:
- Extras
- Defined in:
- lib/unitwise/standard/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Extras
#hash_to_markup
Constructor Details
#initialize(attributes) ⇒ Base
Returns a new instance of Base.
34
35
36
|
# File 'lib/unitwise/standard/base.rb', line 34
def initialize(attributes)
@attributes = attributes
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6
7
8
|
# File 'lib/unitwise/standard/base.rb', line 6
def attributes
@attributes
end
|
Class Method Details
.all ⇒ Object
12
13
14
|
# File 'lib/unitwise/standard/base.rb', line 12
def self.all
@all ||= read
end
|
.hash ⇒ Object
20
21
22
|
# File 'lib/unitwise/standard/base.rb', line 20
def self.hash
self.all.map(&:to_hash)
end
|
.local_key ⇒ Object
8
9
10
|
# File 'lib/unitwise/standard/base.rb', line 8
def self.local_key
remote_key
end
|
.path ⇒ Object
24
25
26
|
# File 'lib/unitwise/standard/base.rb', line 24
def self.path
Unitwise.data_file(local_key)
end
|
.read ⇒ Object
16
17
18
|
# File 'lib/unitwise/standard/base.rb', line 16
def self.read
Unitwise::Standard.hash[remote_key].inject([]){|a,h| a << self.new(h)}
end
|
.write ⇒ Object
28
29
30
31
32
|
# File 'lib/unitwise/standard/base.rb', line 28
def self.write
File.open(path, 'w') do |f|
f.write hash.to_yaml
end
end
|
Instance Method Details
#names ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/unitwise/standard/base.rb', line 38
def names
if attributes["name"].respond_to?(:map)
attributes["name"].map(&:to_s)
else
attributes["name"].to_s
end
end
|
#primary_code ⇒ Object
55
56
57
|
# File 'lib/unitwise/standard/base.rb', line 55
def primary_code
attributes["@Code"]
end
|
#secondary_code ⇒ Object
59
60
61
|
# File 'lib/unitwise/standard/base.rb', line 59
def secondary_code
attributes["@CODE"]
end
|
#symbol ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/unitwise/standard/base.rb', line 46
def symbol
sym = attributes["printSymbol"]
if sym.is_a?(Hash)
hash_to_markup(sym)
elsif sym
sym.to_s
end
end
|
#to_hash ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/unitwise/standard/base.rb', line 63
def to_hash
[:names, :symbol, :primary_code, :secondary_code].inject({}) do |h,a|
if v = self.send(a)
h[a] = v
end
h
end
end
|