Class: Yuriita::Query

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/yuriita/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inputs: []) ⇒ Query

Returns a new instance of Query.



7
8
9
# File 'lib/yuriita/query.rb', line 7

def initialize(inputs: [])
  @inputs = inputs
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



5
6
7
# File 'lib/yuriita/query.rb', line 5

def inputs
  @inputs
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
# File 'lib/yuriita/query.rb', line 11

def ==(other)
  other.is_a?(self.class) && other.inputs == inputs
end

#add_input(input) ⇒ Object Also known as: <<



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

def add_input(input)
  inputs << input
  self
end

#delete(input) ⇒ Object



31
32
33
34
# File 'lib/yuriita/query.rb', line 31

def delete(input)
  inputs.delete(input)
  self
end

#delete_ifObject



36
37
38
39
40
# File 'lib/yuriita/query.rb', line 36

def delete_if
  block_given? or return enum_for(__method__) { size }
  select { |input| yield input }.each { |input| inputs.delete(input) }
  self
end

#each(&block) ⇒ Object



19
20
21
22
23
# File 'lib/yuriita/query.rb', line 19

def each(&block)
  block or return enum_for(__method__) { size }
  inputs.each(&block)
  self
end

#initialize_clone(original) ⇒ Object



52
53
54
55
# File 'lib/yuriita/query.rb', line 52

def initialize_clone(original)
  super
  @inputs = original.instance_variable_get(:@inputs).clone
end

#initialize_dup(original) ⇒ Object



47
48
49
50
# File 'lib/yuriita/query.rb', line 47

def initialize_dup(original)
  super
  @inputs = original.instance_variable_get(:@inputs).dup
end

#keywordsObject



15
16
17
# File 'lib/yuriita/query.rb', line 15

def keywords
  inputs.select{ |input| input.is_a?(Yuriita::Inputs::Keyword) }
end

#sizeObject Also known as: length



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

def size
  inputs.size
end