class Roadie::StyleAttributeBuilder

Public Class Methods

new() click to toggle source
# File lib/roadie/style_attribute_builder.rb, line 3
def initialize
  @styles = []
end

Public Instance Methods

<<(style) click to toggle source
# File lib/roadie/style_attribute_builder.rb, line 7
def <<(style)
  @styles << style
end
attribute_string() click to toggle source
# File lib/roadie/style_attribute_builder.rb, line 11
def attribute_string
  Deduplicator.apply(stable_sort(@styles).map(&:to_s)).join(';')
end

Private Instance Methods

stable_sort(list) click to toggle source
# File lib/roadie/style_attribute_builder.rb, line 16
def stable_sort(list)
  # Ruby's sort is unstable for performance reasons. We need it to be
  # stable, e.g. to preserve order of elements that are compared equal in
  # the sorting.
  # We can accomplish this by using the original array index as a second
  # comparator for when the first one is equal.
  list.each_with_index.sort_by { |item, index| [item, index] }.map(&:first)
end