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

Extended by:
AbstractFormat
Defined in:
card/tmpsets/set/mod035-card-mod-search/self/search.rb,
card/tmpsets/set/mod036-card-mod-search/self/search.rb

Instance Method Summary collapse

Instance Method Details

#add_exact_to_goto_names?(exact, goto_names) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'card/tmpsets/set/mod035-card-mod-search/self/search.rb', line 89

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



67
68
69
70
71
72
73
# File 'card/tmpsets/set/mod035-card-mod-search/self/search.rb', line 67

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

#goto_items(term, exact) ⇒ Object



81
82
83
84
85
86
87
# File 'card/tmpsets/set/mod035-card-mod-search/self/search.rb', line 81

def goto_items term, exact
  goto_names = complete_or_match_search start_only: Card.config.navbox_match_start_only
  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



75
76
77
78
79
# File 'card/tmpsets/set/mod035-card-mod-search/self/search.rb', line 75

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

#term_paramObject



93
94
95
96
97
98
99
# File 'card/tmpsets/set/mod035-card-mod-search/self/search.rb', line 93

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

#view: completeObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'card/tmpsets/set/mod035-card-mod-search/self/search.rb', line 54

view :complete, cache: :never do
  term = term_param
  exact = Card.fetch term, new: {}

  {
    search: true,
    term: term,
    add: add_item(exact),
    new: new_item_of_type(exact),
    goto: goto_items(term, exact)
  }
end