Class: HashtagAutocompleteService::HashtagItem

Inherits:
Object
  • Object
show all
Defined in:
app/services/hashtag_autocomplete_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ HashtagItem

Returns a new instance of HashtagItem.



104
105
106
107
108
109
110
111
112
113
# File 'app/services/hashtag_autocomplete_service.rb', line 104

def initialize(params = {})
  @relative_url = params[:relative_url]
  @text = params[:text]
  @description = params[:description]
  @icon = params[:icon]
  @type = params[:type]
  @ref = params[:ref]
  @slug = params[:slug]
  @id = params[:id]
end

Instance Attribute Details

#descriptionObject

The description text to display in the UI autocomplete menu on hover. This will be things like e.g. category description.



79
80
81
# File 'app/services/hashtag_autocomplete_service.rb', line 79

def description
  @description
end

#iconObject

The icon to display in the UI autocomplete menu for the item.



86
87
88
# File 'app/services/hashtag_autocomplete_service.rb', line 86

def icon
  @icon
end

#idObject

The ID of the resource that is represented by the autocomplete item, e.g. category.id, tag.id



102
103
104
# File 'app/services/hashtag_autocomplete_service.rb', line 102

def id
  @id
end

#refObject

Inserted into the textbox when an autocomplete item is selected, and must be unique so it can be used for lookups via the #lookup method above.



94
95
96
# File 'app/services/hashtag_autocomplete_service.rb', line 94

def ref
  @ref
end

#relative_urlObject

The relative URL for the resource that is represented by the autocomplete item, used for the cooked hashtags, e.g. /c/2/staff



98
99
100
# File 'app/services/hashtag_autocomplete_service.rb', line 98

def relative_url
  @relative_url
end

#secondary_textObject

Some items may want to display extra text in the UI styled differently, e.g. tag topic counts.



75
76
77
# File 'app/services/hashtag_autocomplete_service.rb', line 75

def secondary_text
  @secondary_text
end

#slugObject

Canonical slug for the item. Different from the ref, which can have the type as a suffix to distinguish between conflicts.



83
84
85
# File 'app/services/hashtag_autocomplete_service.rb', line 83

def slug
  @slug
end

#textObject

The text to display in the UI autocomplete menu for the item.



72
73
74
# File 'app/services/hashtag_autocomplete_service.rb', line 72

def text
  @text
end

#typeObject

Distinguishes between different entities e.g. tag, category.



89
90
91
# File 'app/services/hashtag_autocomplete_service.rb', line 89

def type
  @type
end

Instance Method Details

#to_hObject



115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/services/hashtag_autocomplete_service.rb', line 115

def to_h
  {
    relative_url: self.relative_url,
    text: self.text,
    description: self.description,
    icon: self.icon,
    type: self.type,
    ref: self.ref,
    slug: self.slug,
    id: self.id,
  }
end