This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generated_color = (color[0] * 2) + (color[1] * 2) + (color[2] * 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ColorGenerator | |
def initialize(color) | |
@color = color | |
end | |
def generated_color | |
return make_hex(@color.ljust(6, @color)) if (1..2).include?(@color.length) | |
return make_hex(@color.scan(/((.))/).flatten.join) if @color.length == 3 | |
return make_hex(@color.ljust(6, '0')) if (4..5).include?(@color.length) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'color_generator' | |
gem 'minitest' | |
require 'minitest/autorun' | |
class ColorGeneratorTest < Minitest::Test | |
def test_unhandled_color_returns_value_passed_in | |
assert_equal '#d3d3d3', ColorGenerator.new('d3d3d3').generated_color | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ColorGenerator | |
def initialize(color) | |
@color = color | |
end | |
def get_hex(color) | |
case | |
when color.length == 1 | |
generated_color = color * 6 | |
when color.length == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.get_hex(color) | |
case | |
when color.length == 1 | |
generated_color = color * 6 | |
when color.length == 2 | |
generated_color = color * 3 | |
when color.length == 3 | |
generated_color = (color[0] * 2) + (color[1] * 2) + (color[2] * 2) | |
when color.length < 6 && color.length > 3 | |
generated_color = color + ("0" * (6 - color.length)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@categories.insert(insert_at || @categories.size, uncategorized) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insert_uncategorized_category(uncategorized) | |
insert_at = catch(:idx){ | |
@categories.each_with_index do |c, idx| | |
throw(:idx, idx) if (uncategorized.topics_week || 0) > (c.topics_week || 0) | |
end | |
@categories.size | |
} | |
@categories.insert(insert_at, uncategorized) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OLD | |
def insert_uncategorized_category(uncategorized) | |
insert_at = nil | |
@categories.each_with_index do |c, idx| | |
if (uncategorized.topics_week || 0) > (c.topics_week || 0) | |
insert_at = idx | |
break | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_uncategorized | |
# Support for uncategorized topics | |
uncategorized_topics = Topic.uncategorized_topics | |
if uncategorized_topics.present? | |
uncategorized = UncategorizedCategory.new(uncategorized_topics) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UncategorizedCategory < Category | |
def initialize(uncategorized_topics) | |
super({name: SiteSetting.uncategorized_name, | |
slug: Slug.for(SiteSetting.uncategorized_name), | |
color: SiteSetting.uncategorized_color, | |
text_color: SiteSetting.uncategorized_text_color, | |
featured_topics: uncategorized_topics}.merge(Topic.totals)) | |
end | |
end |
NewerOlder