Class: Indexer::Organization

Inherits:
Model
  • Object
show all
Defined in:
lib/indexer/components/organization.rb

Overview

Organization is used to model companies involved in project.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#emailObject

Returns the value of attribute email.



73
74
75
# File 'lib/indexer/components/organization.rb', line 73

def email
  @email
end

#nameObject

Returns the value of attribute name.



64
65
66
# File 'lib/indexer/components/organization.rb', line 64

def name
  @name
end

#rolesObject 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

#websiteObject

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_attributesObject



57
58
59
60
61
# File 'lib/indexer/components/organization.rb', line 57

def initialize_attributes
  @data = {
    :roles => []
  }
end

#to_hObject

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