Class: Twitter::TwitterText::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter-text/configuration.rb

Constant Summary collapse

PARSER_VERSION_CLASSIC =
"v1"
PARSER_VERSION_WEIGHTED =
"v2"
PARSER_VERSION_EMOJI_PARSING =
"v3"
PARSER_VERSION_DEFAULT =
PARSER_VERSION_WEIGHTED
CONFIG_V1 =
File.join(
  File.expand_path('../../../config', __FILE__), # project root
  "#{PARSER_VERSION_CLASSIC}.json"
)
CONFIG_V2 =
File.join(
  File.expand_path('../../../config', __FILE__), # project root
  "#{PARSER_VERSION_WEIGHTED}.json"
)
CONFIG_V3 =
File.join(
  File.expand_path('../../../config', __FILE__), # project root
  "#{PARSER_VERSION_EMOJI_PARSING}.json"
)

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Configuration

Returns a new instance of Configuration.



55
56
57
58
59
60
61
62
63
# File 'lib/twitter-text/configuration.rb', line 55

def initialize(config = {})
  @version = config[:version]
  @max_weighted_tweet_length = config[:maxWeightedTweetLength]
  @scale = config[:scale]
  @default_weight = config[:defaultWeight]
  @transformed_url_length = config[:transformedURLLength]
  @emoji_parsing_enabled = config[:emojiParsingEnabled]
  @ranges = config[:ranges].map { |range| Twitter::TwitterText::WeightedRange.new(range) } if config.key?(:ranges) && config[:ranges].is_a?(Array)
end

Class Attribute Details

.default_configuration ⇒ Object

Returns the value of attribute default_configuration.



19
20
21
# File 'lib/twitter-text/configuration.rb', line 19

def default_configuration
  @default_configuration
end

Instance Attribute Details

#default_weight ⇒ Object (readonly)

Returns the value of attribute default_weight.



23
24
25
# File 'lib/twitter-text/configuration.rb', line 23

def default_weight
  @default_weight
end

#emoji_parsing_enabled ⇒ Object (readonly)

Returns the value of attribute emoji_parsing_enabled.



24
25
26
# File 'lib/twitter-text/configuration.rb', line 24

def emoji_parsing_enabled
  @emoji_parsing_enabled
end

#max_weighted_tweet_length ⇒ Object (readonly)

Returns the value of attribute max_weighted_tweet_length.



22
23
24
# File 'lib/twitter-text/configuration.rb', line 22

def max_weighted_tweet_length
  @max_weighted_tweet_length
end

#ranges ⇒ Object (readonly)

Returns the value of attribute ranges.



23
24
25
# File 'lib/twitter-text/configuration.rb', line 23

def ranges
  @ranges
end

#scale ⇒ Object (readonly)

Returns the value of attribute scale.



22
23
24
# File 'lib/twitter-text/configuration.rb', line 22

def scale
  @scale
end

#transformed_url_length ⇒ Object (readonly)

Returns the value of attribute transformed_url_length.



23
24
25
# File 'lib/twitter-text/configuration.rb', line 23

def transformed_url_length
  @transformed_url_length
end

#version ⇒ Object (readonly)

Returns the value of attribute version.



22
23
24
# File 'lib/twitter-text/configuration.rb', line 22

def version
  @version
end

Class Method Details

.configuration_from_file(filename) ⇒ Object



50
51
52
53
# File 'lib/twitter-text/configuration.rb', line 50

def self.configuration_from_file(filename)
  config = parse_file(filename)
  config ? self.new(config) : nil
end

.parse_file(filename) ⇒ Object



45
46
47
48
# File 'lib/twitter-text/configuration.rb', line 45

def self.parse_file(filename)
  string = File.open(filename, 'rb') { |f| f.read }
  parse_string(string)
end

.parse_string(string, options = {}) ⇒ Object



41
42
43
# File 'lib/twitter-text/configuration.rb', line 41

def self.parse_string(string, options = {})
  JSON.parse(string, options.merge(symbolize_names: true))
end