class Relaton::FullTextSeatch

Attributes

regex[R]

@return Regexp

Public Class Methods

new(collection) click to toggle source

@param collection [Relaton::Bibcollection]

# File lib/relaton/cli/full_text_search.rb, line 13
def initialize(collection)
  @collection = collection
end

Public Instance Methods

any?() click to toggle source

@return [Boolean]

# File lib/relaton/cli/full_text_search.rb, line 37
def any?
  @matches.any?
end
print_results() click to toggle source

Private Instance Methods

message(match) click to toggle source

@param match [MatchData] @return [String]

# File lib/relaton/cli/full_text_search.rb, line 83
def message(match)
  msg = ""
  msg += "..." unless match[1].empty?
  msg += "#{match[2]}\e[4m#{match[3]}\e[24m#{match[4]}"
  msg += "..." unless match[5].empty?
  msg
end
print_attrs(attrs, indent) click to toggle source

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity

result(item) click to toggle source

@param item [Relaton::Bibdata] @return [Hash]

# File lib/relaton/cli/full_text_search.rb, line 62
def result(item)
  if item.is_a? String
    message $~ if item.match regex
  elsif item.respond_to? :reduce
    item.reduce([]) do |m, i|
      res = result i
      m << res if res && !res.empty?
      m
    end
  else
    item.instance_variables.reduce({}) do |m, var|
      res = result item.instance_variable_get(var)
      m[var.to_s.tr(":@", "")] = res if res && !res.empty?
      m
    end
  end
end