Class: Libis::Tools::Metadata::SubfieldCriteriaParser
- Inherits:
-
BasicParser
show all
- Defined in:
- lib/libis/tools/metadata/parser/subfield_criteria_parser.rb
Overview
Instance Method Summary
collapse
Methods inherited from BasicParser
#any_quoted, #complement, #grouped, #grouped_anonymous, #transformer
Instance Method Details
#criteria_to_s(criteria) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/libis/tools/metadata/parser/subfield_criteria_parser.rb', line 28
def criteria_to_s(criteria)
case criteria
when Array
when Hash
criteria = [criteria]
else
return criteria
end
criteria.map { |selection| selection_to_s(selection) }.join(' ')
end
|
#match_criteria(criteria, data) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/libis/tools/metadata/parser/subfield_criteria_parser.rb', line 49
def match_criteria(criteria, data)
tree = self.new.parse(criteria)
return true if tree.is_a? String
tree = [tree] unless tree.is_a? Array
tree.map { |selection| match_selection(selection, data) }.any?
end
|
#match_selection(selection, data) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/libis/tools/metadata/parser/subfield_criteria_parser.rb', line 56
def match_selection(selection, data)
must_match = selection[:must].to_s.split('')
return false unless must_match == (must_match & data)
one_of = selection[:one_of].to_s.split('')
return false unless one_of.empty? || (one_of & data).any?
only_one_of = selection[:only_one_of].to_s.split('')
return false unless only_one_of.empty? || (only_one_of & data).size != 1
return false if match_selection(selection[:not], data) if selection[:not]
true
end
|
#selection_to_s(selection) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/libis/tools/metadata/parser/subfield_criteria_parser.rb', line 40
def selection_to_s(selection)
return selection unless selection.is_a? Hash
result = "#{selection[:must]}"
result += "(#{selection[:one_of]})" if selection[:one_of]
result += "{#{selection[:only_one_of]}}" if selection[:only_one_of]
result += "-#{selection_to_s(selection[:not])}" if selection[:not]
result
end
|