Class: AwesomeTranslations::Group
- Inherits:
-
Object
- Object
- AwesomeTranslations::Group
- Defined in:
- app/models/awesome_translations/group.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Group
constructor
A new instance of Group.
- #inspect ⇒ Object
- #name ⇒ Object
- #to_param ⇒ Object
- #to_s ⇒ Object
- #translations(args = {}) ⇒ Object
Constructor Details
#initialize(args) ⇒ Group
Returns a new instance of Group.
12 13 14 15 16 17 |
# File 'app/models/awesome_translations/group.rb', line 12 def initialize(args) @handler = args.fetch(:handler) @id = args.fetch(:id) @data = args[:data] || {} raise "Invalid ID: #{@id}" if @id.blank? end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
2 3 4 |
# File 'app/models/awesome_translations/group.rb', line 2 def data @data end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
2 3 4 |
# File 'app/models/awesome_translations/group.rb', line 2 def handler @handler end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'app/models/awesome_translations/group.rb', line 2 def id @id end |
Class Method Details
.find_by(handler:, id:) ⇒ Object
4 5 6 7 8 9 10 |
# File 'app/models/awesome_translations/group.rb', line 4 def self.find_by(handler:, id:) handler.groups.each do |group| return group if group.id == id.to_s end raise ActiveRecord::RecordNotFound, "Group not found by handler and ID: '#{handler.name}', '#{id}'." end |
Instance Method Details
#inspect ⇒ Object
47 48 49 |
# File 'app/models/awesome_translations/group.rb', line 47 def inspect to_s end |
#name ⇒ Object
39 40 41 |
# File 'app/models/awesome_translations/group.rb', line 39 def name @data[:name].presence || id.presence end |
#to_param ⇒ Object
35 36 37 |
# File 'app/models/awesome_translations/group.rb', line 35 def to_param id end |
#to_s ⇒ Object
43 44 45 |
# File 'app/models/awesome_translations/group.rb', line 43 def to_s "<AwesomeTranslations::Group id=\"#{@id}\" name=\"#{name}\">" end |
#translations(args = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/awesome_translations/group.rb', line 19 def translations(args = {}) translations_list = @handler.translations_for_group(self) args.each do |key, value| if key == :finished translations_list = translations_list.select(&:finished?) if value elsif key == :unfinished translations_list = translations_list.select(&:unfinished?) if value else raise "Unknown key: #{key}" end end translations_list end |