Class: Unitwise::Base
- Inherits:
-
Object
- Object
- Unitwise::Base
- Defined in:
- lib/unitwise/base.rb
Instance Attribute Summary collapse
-
#names ⇒ Object
Returns the value of attribute names.
-
#primary_code ⇒ Object
Returns the value of attribute primary_code.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#secondary_code ⇒ Object
Returns the value of attribute secondary_code.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Base
constructor
A new instance of Base.
- #slugs ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Base
30 31 32 33 34 |
# File 'lib/unitwise/base.rb', line 30 def initialize(attrs) attrs.each do |k, v| public_send :"#{k}=", v end end |
Instance Attribute Details
#names ⇒ Object
Returns the value of attribute names.
5 6 7 |
# File 'lib/unitwise/base.rb', line 5 def names @names end |
#primary_code ⇒ Object
Returns the value of attribute primary_code.
4 5 6 |
# File 'lib/unitwise/base.rb', line 4 def primary_code @primary_code end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
5 6 7 |
# File 'lib/unitwise/base.rb', line 5 def scale @scale end |
#secondary_code ⇒ Object
Returns the value of attribute secondary_code.
4 5 6 |
# File 'lib/unitwise/base.rb', line 4 def secondary_code @secondary_code end |
#symbol ⇒ Object
Returns the value of attribute symbol.
4 5 6 |
# File 'lib/unitwise/base.rb', line 4 def symbol @symbol end |
Class Method Details
.all ⇒ Object
7 8 9 |
# File 'lib/unitwise/base.rb', line 7 def self.all @all ||= data.map{|d| self.new d } end |
.find(string) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/unitwise/base.rb', line 11 def self.find(string) [:primary_code, :secondary_code, :names, :slugs, :symbol].reduce(nil) do |m, method| if found = find_by(method, string) return found end end end |
.find_by(method, string) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/unitwise/base.rb', line 19 def self.find_by(method, string) self.all.find do |i| key = i.send(method) if key.respond_to?(:each) key.include?(string) else key == string end end end |
Instance Method Details
#slugs ⇒ Object
40 41 42 |
# File 'lib/unitwise/base.rb', line 40 def slugs names.map(&:to_slug) end |