Class: Indexer::Organization
- Defined in:
- lib/indexer/components/organization.rb
Overview
Organization is used to model companies involved in project.
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
-
#roles ⇒ Object
(also: #role, #group, #team)
List of roles the person plays in the project.
-
#website ⇒ Object
Returns the value of attribute website.
Class Method Summary collapse
-
.parse(entry) ⇒ Object
Parse
entry
and create Organization object. - .parse_array(array) ⇒ Object
- .parse_string(string) ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Object
CONSIDER: Only name has to be equal?.
-
#initialize(data) ⇒ Organization
constructor
A new instance of Organization.
- #initialize_attributes ⇒ Object
-
#to_h ⇒ Object
Convert to simple Hash represepentation.
Methods inherited from Model
#[], #[]=, attr_reader, attr_writer, #key?, #merge!, #method_missing, #store, #to_yaml, #validate
Constructor Details
#initialize(data) ⇒ Organization
Returns a new instance of Organization.
51 52 53 54 |
# File 'lib/indexer/components/organization.rb', line 51 def initialize(data) super(data) #raise ArgumentError, "person must have a name" unless name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Indexer::Model
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
73 74 75 |
# File 'lib/indexer/components/organization.rb', line 73 def email @email end |
#name ⇒ Object
Returns the value of attribute name.
64 65 66 |
# File 'lib/indexer/components/organization.rb', line 64 def name @name end |
#roles ⇒ Object Also known as: role, group, team
List of roles the person plays in the project. This can be any string or array of strings.
92 93 94 |
# File 'lib/indexer/components/organization.rb', line 92 def roles @roles end |
#website ⇒ Object
Returns the value of attribute website.
82 83 84 |
# File 'lib/indexer/components/organization.rb', line 82 def website @website end |
Class Method Details
.parse(entry) ⇒ Object
Parse entry
and create Organization object.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/indexer/components/organization.rb', line 8 def self.parse(entry) case entry when Organization entry when String parse_string(entry) when Array parse_array(entry) when Hash new(entry) end end |
.parse_array(array) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/indexer/components/organization.rb', line 22 def self.parse_array(array) data = {} array.each do |value| v = value.strip case v when /^(.*?)\s*\<(.*?@.*?)\>/ data[:name] = $1 unless $1.empty? data[:email] = $2 when /^(http|https)\:/ data[:website] = v when /\@/ data[:email] = v else data[:name] = v end end new(data) end |
.parse_string(string) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/indexer/components/organization.rb', line 42 def self.parse_string(string) if md = /(.*?)\s*\<(.*?)\>/.match(string) new(:name=>md[1], :email=>md[2]) else new(:name=>string) end end |
Instance Method Details
#==(other) ⇒ Object
CONSIDER: Only name has to be equal?
126 127 128 129 130 |
# File 'lib/indexer/components/organization.rb', line 126 def ==(other) return false unless Organization === other return false unless name == other.name return true end |
#initialize_attributes ⇒ Object
57 58 59 60 61 |
# File 'lib/indexer/components/organization.rb', line 57 def initialize_attributes @data = { :roles => [] } end |
#to_h ⇒ Object
Convert to simple Hash represepentation.
116 117 118 119 120 121 122 123 |
# File 'lib/indexer/components/organization.rb', line 116 def to_h h = {} h['name'] = name h['email'] = email if email h['website'] = website if website h['roles'] = roles if not roles.empty? h end |