Class: Jamef::Branch

Inherits:
OpenStruct
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/jamef/branch.rb

Class Method Summary collapse

Class Method Details

.allObject



28
29
30
# File 'lib/jamef/branch.rb', line 28

def self.all
  branches.map{|k,v| v}
end

.branchesObject



11
12
13
# File 'lib/jamef/branch.rb', line 11

def self.branches
  @branches ||= {}
end

.create(branch_hash) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
# File 'lib/jamef/branch.rb', line 20

def self.create branch_hash
  raise(ArgumentError,'branch_hash should be a hash. Got #{branch.class} instead.') unless branch_hash.is_a?(Hash)
  branch = new(branch_hash)
  raise("Can not create an invalid branch") unless branch.valid?
  branches.store(branch.id,branch)
  branch
end

.find(id) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
# File 'lib/jamef/branch.rb', line 15

def self.find id
  raise ArgumentError, 'Id must be a String or Symbol' unless id.class.in?([Symbol, String])
  branches[id.to_sym]
end

.firstObject



32
33
34
# File 'lib/jamef/branch.rb', line 32

def self.first
  all.first
end

.lastObject



36
37
38
# File 'lib/jamef/branch.rb', line 36

def self.last
  all.last
end

.populateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jamef/branch.rb', line 41

def self.populate
  [  
    { id: :aracaju, code: '31', initials: 'AJU' , location: 'Aracaju - SE' },
    { id: :barueri, code: '19', initials: 'BAR' , location: 'Barueri - SP' },
    { id: :bauru, code: '16', initials: 'BAU' , location: 'Bauru - SP' },
    { id: :belo_horizonte, code: '02', initials: 'BHZ' , location: 'Belo Horizonte - MG' },
    { id: :blumenau, code: '09', initials: 'BNU' , location: 'Blumenau - SC' },
    { id: :brasilia, code: '28', initials: 'BSB' , location: 'Brasília - DF' },
    { id: :criciuma, code: '26', initials: 'CCM' , location: 'Criciúma - SC' },
    { id: :campinas, code: '03', initials: 'CPQ' , location: 'Campinas - SP' },
    { id: :caxias_do_sul, code: '22', initials: 'CXJ' , location: 'Caxias do Sul - RS' },
    { id: :curitiba, code: '04', initials: 'CWB' , location: 'Curitiba - PR' },
    { id: :divinopolis, code: '38', initials: 'DIV' , location: 'Divinópolis - MG' },
    { id: :feira_de_santana, code: '34', initials: 'FES' , location: 'Feira de Santana - BA' },
    { id: :florianopolis, code: '11', initials: 'FLN' , location: 'Florianópolis - SC' },
    { id: :fortaleza, code: '32', initials: 'FOR' , location: 'Fortaleza - CE' },
    { id: :goiania, code: '24', initials: 'GYN' , location: 'Goiânia - GO' },
    { id: :joao_pessoa, code: '36', initials: 'JPA' , location: 'João Pessoa - PB' },
    { id: :juiz_de_fora, code: '23', initials: 'JDF' , location: 'Juiz de Fora - MG' },
    { id: :joinville, code: '08', initials: 'JOI' , location: 'Joinville - SC' },
    { id: :londrina, code: '10', initials: 'LDB' , location: 'Londrina - PR' },
    { id: :manaus, code: '25', initials: 'MAO' , location: 'Manaus - AM' },
    { id: :maceio, code: '33', initials: 'MCZ' , location: 'Maceió - AL' },
    { id: :maringa, code: '12', initials: 'MGF' , location: 'Maringá - PR' },
    { id: :porto_alegre, code: '05', initials: 'POA' , location: 'Porto Alegre - RS' },
    { id: :pouso_alegre, code: '27', initials: 'PSA' , location: 'Pouso Alegre - MG' },
    { id: :ribeirao_preto, code: '18', initials: 'RAO' , location: 'Ribeirão Preto - SP' },
    { id: :recife, code: '30', initials: 'REC' , location: 'Recife - PE' },
    { id: :rio_de_janeiro, code: '06', initials: 'RIO' , location: 'Rio de Janeiro - RJ' },
    { id: :sao_paulo, code: '07', initials: 'SAO' , location: 'São Paulo - SP' },
    { id: :sao_jose_dos_campos, code: '21', initials: 'SJK', location: 'São José dos Campos - SP' },
    { id: :sao_jose_do_rio_preto, code: '20', initials: 'SJP', location: 'São José do Rio Preto - SP' },
    { id: :salvador, code: '29', initials: 'SSA', location: 'Salvador - BA' },
    { id: :uberlandia, code: '17', initials: 'UDI', location: 'Uberlândia - MG' },
    { id: :vitoria_da_conquista, code: '39', initials: 'VDC', location: 'Vitória da Conquista - BA' },
    { id: :vitoria, code: '14', initials: 'VIX', location: 'Vitória - ES' }
  ].each {|branch| create(branch) }
end