Skip to content

Commit

Permalink
Store scope and type as Symbols
Browse files Browse the repository at this point in the history
for lower memory-footprint
  • Loading branch information
bbenno committed Jun 8, 2022
1 parent 5b7604e commit 5426c6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ language.alpha2 # => :fr (alias for #iso639_1)
language.alpha3 # => :fra (alias for #iso639_3)
language.alpha3_bibliographic # => :fre (alias for #iso_639_2b)
language.alpha3_terminology # => :fra (alias for #iso_639_2t)
language.type # => "living"
language.scope # => "individual"
language.type # => :living
language.scope # => :individual
language.extinct? # => false
language.living? # => true
Expand Down
10 changes: 5 additions & 5 deletions lib/languages/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class Language

attr_reader :iso639_1, :iso639_2b, :iso639_2t, :iso639_3, :scope, :type, :name # , :comment

def initialize(csv_attributes) # rubocop:disable Metrics/AbcSize
def initialize(csv_attributes) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
@iso639_3 = csv_attributes.fetch(:id).to_sym
@iso639_2b = csv_attributes.fetch(:part2b)&.to_sym
@iso639_2t = csv_attributes.fetch(:part2t)&.to_sym
@iso639_1 = csv_attributes.fetch(:part1)&.to_sym
@scope = SCOPES.detect { |s| s.chr.upcase == csv_attributes.fetch(:scope) }
@type = TYPES.detect { |t| t.chr.upcase == csv_attributes.fetch(:language_type) }
@scope = SCOPES.detect { |s| s.chr.upcase == csv_attributes.fetch(:scope) }&.to_sym
@type = TYPES.detect { |t| t.chr.upcase == csv_attributes.fetch(:language_type) }&.to_sym
@name = csv_attributes.fetch(:ref_name)
# @comment = csv_attributes.fetch(:comment)
end
Expand All @@ -32,7 +32,7 @@ def to_s

TYPES.each do |type|
define_method "#{type}?" do
self.type == type
self.type == type.to_sym
end
end

Expand All @@ -41,7 +41,7 @@ def to_s
method_name = scope.end_with?('language') ? scope : "#{scope}_language"

define_method "#{method_name}?" do
self.scope == scope
self.scope == scope.to_sym
end
end

Expand Down

0 comments on commit 5426c6d

Please sign in to comment.