Class: Hashtags::Builder
- Inherits:
-
Struct
- Object
- Struct
- Hashtags::Builder
- Defined in:
- lib/hashtags/builder.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .dom_data(options = {}) ⇒ Object
- .help(options = {}) ⇒ Object
- .to_hashtag(str, options = {}) ⇒ Object
- .to_markup(str, options = {}) ⇒ Object
- .used_hashtag_classes(str, options = {}) ⇒ Object
Instance Method Summary collapse
-
#dom_data ⇒ Object
render textcomplete dom data.
- #filter_classes(cls) ⇒ Object
- #hashtag_classes ⇒ Object
-
#help ⇒ Object
render help string.
-
#initialize(options = {}) ⇒ Builder
constructor
A new instance of Builder.
-
#to_hashtag(str) ⇒ Object
collects hashtags from all hashtags classes.
-
#to_markup(str) ⇒ Object
collects markup from all hashtags classes.
Constructor Details
#initialize(options = {}) ⇒ Builder
Returns a new instance of Builder.
25 26 27 |
# File 'lib/hashtags/builder.rb', line 25 def initialize( = {}) super() end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options
2 3 4 |
# File 'lib/hashtags/builder.rb', line 2 def end |
Class Method Details
.dom_data(options = {}) ⇒ Object
17 18 19 |
# File 'lib/hashtags/builder.rb', line 17 def self.dom_data( = {}) new().dom_data end |
.help(options = {}) ⇒ Object
21 22 23 |
# File 'lib/hashtags/builder.rb', line 21 def self.help( = {}) new().help end |
.to_hashtag(str, options = {}) ⇒ Object
7 8 9 |
# File 'lib/hashtags/builder.rb', line 7 def self.to_hashtag(str, = {}) new().to_hashtag(str) end |
.to_markup(str, options = {}) ⇒ Object
3 4 5 |
# File 'lib/hashtags/builder.rb', line 3 def self.to_markup(str, = {}) new().to_markup(str) end |
.used_hashtag_classes(str, options = {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/hashtags/builder.rb', line 11 def self.used_hashtag_classes(str, = {}) new().hashtag_classes.select do |cls| cls.regexp.match?(str) end end |
Instance Method Details
#dom_data ⇒ Object
render textcomplete dom data
40 41 42 43 44 45 |
# File 'lib/hashtags/builder.rb', line 40 def dom_data { hashtags: { path: Engine.routes.url_helpers., strategies: hashtag_strategies } } end |
#filter_classes(cls) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/hashtags/builder.rb', line 54 def filter_classes(cls) return [] unless cls.present? res = cls res &= [:only] if [:only] res -= [:except] if [:except] res end |
#hashtag_classes ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/hashtags/builder.rb', line 62 def hashtag_classes filter_classes( Resource.resource_classes + User.user_classes + Variable.variable_classes ) end |
#help ⇒ Object
render help string
48 49 50 51 52 |
# File 'lib/hashtags/builder.rb', line 48 def help hashtag_classes.group_by(&:trigger).map do |trigger, cls| OpenStruct.new(hashtag_classes: cls, trigger: trigger, help_values: cls.map(&:help_values).flatten.compact.sort) end end |
#to_hashtag(str) ⇒ Object
collects hashtags from all hashtags classes
35 36 37 |
# File 'lib/hashtags/builder.rb', line 35 def to_hashtag(str) hashtag_classes.inject(str) { |res, cls| cls.to_hashtag(res) } end |
#to_markup(str) ⇒ Object
collects markup from all hashtags classes
30 31 32 |
# File 'lib/hashtags/builder.rb', line 30 def to_markup(str) hashtag_classes.inject(str) { |res, cls| cls.to_markup(res) } end |