lib/languages/language.rb in human_languages-0.5.0 vs lib/languages/language.rb in human_languages-0.6.0

- old
+ new

@@ -5,17 +5,17 @@ class Language include Comparable 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 alias iso639_2 iso639_2t @@ -30,19 +30,19 @@ name.to_s # Enforce return of String, even if name is nil end TYPES.each do |type| define_method "#{type}?" do - self.type == type + self.type == type.to_sym end end SCOPES.each do |scope| # prevent ambiguity of scope "special" and type "special" method_name = scope.end_with?('language') ? scope : "#{scope}_language" define_method "#{method_name}?" do - self.scope == scope + self.scope == scope.to_sym end end def ==(other) other.class == self.class && other.iso639_3 == iso639_3