Class: Yuriita::Table

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/yuriita/table.rb

Constant Summary collapse

SPACE =
" ".freeze
EMPTY_STRING =
"".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation:, params:, configuration:, param_key: :q) ⇒ Table

Returns a new instance of Table.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yuriita/table.rb', line 12

def initialize(
  relation:,
  params:,
  configuration:,
  param_key: :q
)
  @relation = relation
  @params = params
  @configuration = configuration
  @param_key = param_key
  @search = Yuriita::Search.new(self, @param_key)
end

Instance Attribute Details

#searchObject (readonly)

Returns the value of attribute search.



25
26
27
# File 'lib/yuriita/table.rb', line 25

def search
  @search
end

Instance Method Details

#default_inputObject



50
51
52
# File 'lib/yuriita/table.rb', line 50

def default_input
  configuration.default_input
end

#filtered?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/yuriita/table.rb', line 46

def filtered?
  user_input? && user_query != default_query
end

#itemsObject



42
43
44
# File 'lib/yuriita/table.rb', line 42

def items
  Runner.new(relation: relation, configuration: configuration).run(query)
end

#qObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yuriita/table.rb', line 27

def q
  output =
    if user_input?
      user_input
    else
      default_input
    end

  if output.blank?
    EMPTY_STRING
  else
    output + SPACE
  end
end