Class: AppInfo::Protobuf::Resources::Entry

Inherits:
Object
  • Object
show all
Includes:
Helper::GenerateClass
Defined in:
lib/app_info/protobuf/resources.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper::GenerateClass

#create_class, #define_instance_method

Constructor Details

#initialize(doc, package) ⇒ Entry

Returns a new instance of Entry.



126
127
128
129
130
# File 'lib/app_info/protobuf/resources.rb', line 126

def initialize(doc, package)
  @package = package
  @name = doc.name
  parse(doc)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



124
125
126
# File 'lib/app_info/protobuf/resources.rb', line 124

def name
  @name
end

#valuesObject (readonly)

Returns the value of attribute values.



124
125
126
# File 'lib/app_info/protobuf/resources.rb', line 124

def values
  @values
end

Class Method Details

.parse_from(type, package) ⇒ Object



118
119
120
121
122
# File 'lib/app_info/protobuf/resources.rb', line 118

def self.parse_from(type, package)
  type.entry.each_with_object([]) do |entry, obj|
    obj << Entry.new(entry, package)
  end
end

Instance Method Details

#first_valueObject



139
140
141
# File 'lib/app_info/protobuf/resources.rb', line 139

def first_value
  @first_value ||= @values[0]
end

#localesObject



143
144
145
# File 'lib/app_info/protobuf/resources.rb', line 143

def locales
  @locales ||= @values.map(&:locale)
end

#value(locale: '') ⇒ Object



132
133
134
135
136
137
# File 'lib/app_info/protobuf/resources.rb', line 132

def value(locale: '')
  values = @values.select { |v| v.locale == locale }
  return first_value if values.empty?

  values.size == 1 ? values[0] : values
end