Module: Card::Set::Self::Search::JsonFormat

Extended by:
AbstractFormat
Defined in:
tmpsets/set/mod020-search/self/search.rb

Instance Method Summary collapse

Instance Method Details

#add_exact_to_goto_names?(exact, goto_names) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'tmpsets/set/mod020-search/self/search.rb', line 90

def add_exact_to_goto_names? exact, goto_names
  exact.known? && !goto_names.find { |n| n.to_name.key == exact.key }
end

#add_item(exact) ⇒ Object



68
69
70
71
72
73
74
# File 'tmpsets/set/mod020-search/self/search.rb', line 68

def add_item exact
  return unless exact.new_card? &&
                exact.name.valid? &&
                !exact.virtual? &&
                exact.ok?(:create)
  [h(exact.name), exact.name.url_key]
end

#goto_items(term, exact) ⇒ Object



82
83
84
85
86
87
88
# File 'tmpsets/set/mod020-search/self/search.rb', line 82

def goto_items term, exact
  goto_names = complete_or_match_search
  goto_names.unshift exact.name if add_exact_to_goto_names? exact, goto_names
  goto_names.map do |name|
    [name, name.to_name.url_key, h(highlight(name, term, sanitize: false))]
  end
end

#new_item_of_type(exact) ⇒ Object



76
77
78
79
80
# File 'tmpsets/set/mod020-search/self/search.rb', line 76

def new_item_of_type exact
  return unless (exact.type_id == Card::CardtypeID) &&
                Card.new(type_id: exact.id).ok?(:create)
  [exact.name, "new/#{exact.name.url_key}"]
end

#term_paramObject



94
95
96
97
98
99
100
# File 'tmpsets/set/mod020-search/self/search.rb', line 94

def term_param
  term = query_params[:keyword]
  if (term =~ /^\+/) && (main = params["main"])
    term = main + term
  end
  term
end