Class: PlanMyStuff::IssueFieldValueSet
- Inherits:
-
Object
- Object
- PlanMyStuff::IssueFieldValueSet
- Includes:
- Enumerable
- Defined in:
- lib/plan_my_stuff/issue_field_value_set.rb
Overview
Hash-like read-side view of GitHub Issue Field values on a single Issue. Returned by Issue#issue_fields. Values are coerced into Ruby types on construction: date fields come back as Date, number fields as Float, single-select fields as the option name String, and text fields as the raw String.
Access is by canonical field name (consumer names / values are reverse-translated via PlanMyStuff::IssueFieldTranslation on construction); string and symbol keys both work. Iteration yields [name, value] pairs in the order GitHub returned them.
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object?
- #each ⇒ Enumerator, void
-
#initialize(hash) ⇒ IssueFieldValueSet
constructor
A new instance of IssueFieldValueSet.
-
#to_h ⇒ Hash{String => Object}
Copy of the underlying hash.
Constructor Details
#initialize(hash) ⇒ IssueFieldValueSet
Returns a new instance of IssueFieldValueSet.
46 47 48 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 46 def initialize(hash) @hash = hash end |
Class Method Details
.coerce(node) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 34 def coerce(node) case node[:__typename].to_s when 'IssueFieldDateValue' then Date.parse(node.fetch(:value)) when 'IssueFieldNumberValue' then node.fetch(:value).to_f when 'IssueFieldSingleSelectValue' then node.fetch(:name) else node.fetch(:value) end end |
.from_graphql(nodes) ⇒ PlanMyStuff::IssueFieldValueSet
22 23 24 25 26 27 28 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 22 def from_graphql(nodes) pairs = Array.wrap(nodes).map do |node| canonical_name = PlanMyStuff::IssueFieldTranslation.canonical_field_name(node.dig(:field, :name)) [canonical_name, PlanMyStuff::IssueFieldTranslation.canonical_value(canonical_name, coerce(node))] end new(pairs.to_h) end |
Instance Method Details
#[](name) ⇒ Object?
54 55 56 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 54 def [](name) @hash[name.to_s] end |
#each ⇒ Enumerator, void
64 65 66 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 64 def each(&) @hash.each(&) end |
#to_h ⇒ Hash{String => Object}
Returns copy of the underlying hash.
59 60 61 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 59 def to_h @hash.dup end |