Class: Ghaki::Meta::Dict::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/ghaki/meta/dict/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStorage

Returns a new instance of Storage.



9
10
11
12
13
# File 'lib/ghaki/meta/dict/storage.rb', line 9

def initialize
  @snake = {}
  @title = {}
  @camel = {}
end

Instance Attribute Details

#camelObject

Returns the value of attribute camel.



7
8
9
# File 'lib/ghaki/meta/dict/storage.rb', line 7

def camel
  @camel
end

#snakeObject

Returns the value of attribute snake.



7
8
9
# File 'lib/ghaki/meta/dict/storage.rb', line 7

def snake
  @snake
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/ghaki/meta/dict/storage.rb', line 7

def title
  @title
end

Instance Method Details

#get_camel(token) ⇒ Object



39
40
41
42
43
44
# File 'lib/ghaki/meta/dict/storage.rb', line 39

def get_camel token
  if @camel[token].nil?
    put_camel token, title_to_camel( get_title(token) )
  end
  @camel[token]
end

#get_snake(token) ⇒ Object



25
26
27
28
29
30
# File 'lib/ghaki/meta/dict/storage.rb', line 25

def get_snake token
  if @snake[token].nil?
    raise ArgumentError, "Unknown Token: #{token}"
  end
  @snake[token]
end

#get_title(token) ⇒ Object



32
33
34
35
36
37
# File 'lib/ghaki/meta/dict/storage.rb', line 32

def get_title token
  if @title[token].nil?
    put_title token, snake_to_title( get_snake(token) )
  end
  @title[token] 
end

#opt_alias(opts, put, get) ⇒ Object



52
53
54
# File 'lib/ghaki/meta/dict/storage.rb', line 52

def opt_alias opts, put, get
  put_snake put, (opts[put] || get_snake(get))
end

#opt_plural(opts, put, get) ⇒ Object



49
50
51
# File 'lib/ghaki/meta/dict/storage.rb', line 49

def opt_plural opts, put, get
  put_snake put, (opts[put] || get_snake(get) + 's')
end

#opt_set(opts, put, value) ⇒ Object



46
47
48
# File 'lib/ghaki/meta/dict/storage.rb', line 46

def opt_set opts, put, value
  put_snake put, (opts[put] || value)
end

#snake_to_camel(text) ⇒ Object



62
63
64
# File 'lib/ghaki/meta/dict/storage.rb', line 62

def snake_to_camel text
  title_to_camel snake_to_title(text)
end

#snake_to_title(text) ⇒ Object



56
57
58
# File 'lib/ghaki/meta/dict/storage.rb', line 56

def snake_to_title text
  text.split('_').map do |x| x.capitalize end.join(' ')
end

#title_to_camel(text) ⇒ Object



59
60
61
# File 'lib/ghaki/meta/dict/storage.rb', line 59

def title_to_camel text
  text.gsub(' ','')
end