Class: Transcriber::Resource::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/transcriber/resource/key.rb

Direct Known Subclasses

Association, Href, Property

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Key

Returns a new instance of Key.



6
7
8
9
# File 'lib/transcriber/resource/key.rb', line 6

def initialize(name, options = {})
  @name    = name
  @options = options
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



4
5
6
# File 'lib/transcriber/resource/key.rb', line 4

def model
  @model
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/transcriber/resource/key.rb', line 4

def name
  @name
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/transcriber/resource/key.rb', line 4

def options
  @options
end

#summarizeObject

Returns the value of attribute summarize.



4
5
6
# File 'lib/transcriber/resource/key.rb', line 4

def summarize
  @summarize
end

Instance Method Details

#convert_input_keysObject



11
12
13
14
# File 'lib/transcriber/resource/key.rb', line 11

def convert_input_keys
  options.fetch(:convert_input_keys, model.try(:convert_input_keys) ||
                Transcriber.configuration.convert_input_keys)
end

#input_pathObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/transcriber/resource/key.rb', line 16

def input_path
  return @input_path.clone if @input_path

  @input_path = InputPath.resolve(options, convert_input_keys)

  if @input_path.empty? and !root_path?
    @input_path = convert_input_keys.call([name])
  end

  @input_path.clone
end

#present?(resource) ⇒ Boolean

Returns:



33
34
35
# File 'lib/transcriber/resource/key.rb', line 33

def present?(resource)
  !options[:if] ? true : resource.instance_eval(&options[:if])
end

#root_path?Boolean

Returns:



28
29
30
31
# File 'lib/transcriber/resource/key.rb', line 28

def root_path?
  path_definition = options.slice(:start_key, :field)
  path_definition.any? and path_definition.first[1].empty?
end

#visible?(resource) ⇒ Boolean

Returns:



37
38
39
40
41
42
43
# File 'lib/transcriber/resource/key.rb', line 37

def visible?(resource)
  !present?(resource) ? false : case visible = options[:visible]
                                when nil  then true
                                when Proc then resource.instance_eval(&visible)
                                else visible
                                end
end