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 field display name; 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.
42 43 44 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 42 def initialize(hash) @hash = hash end |
Class Method Details
.coerce(node) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 30 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
21 22 23 24 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 21 def from_graphql(nodes) pairs = Array.wrap(nodes).map { |node| [node.dig(:field, :name), coerce(node)] } new(pairs.to_h) end |
Instance Method Details
#[](name) ⇒ Object?
50 51 52 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 50 def [](name) @hash[name.to_s] end |
#each ⇒ Enumerator, void
60 61 62 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 60 def each(&) @hash.each(&) end |
#to_h ⇒ Hash{String => Object}
Returns copy of the underlying hash.
55 56 57 |
# File 'lib/plan_my_stuff/issue_field_value_set.rb', line 55 def to_h @hash.dup end |