Module: Tins::Duration::ConnectorResolver
- Included in:
- Tins::Duration, Tins::Duration
- Defined in:
- lib/tins/duration.rb
Overview
Resolves a HUMAN_CONNECTORS preset to its connector hash.
Shared by #to_human and parse_human so that both
accept the same connector: keyword argument without
duplicating the nil / Symbol / Hash dispatch.
Instance Method Summary collapse
-
#resolve_connector(connector, style) ⇒ Hash
Resolves a connector specification to a
Hashwith keys:words,:two_words, and:last_word.
Instance Method Details
#resolve_connector(connector, style) ⇒ Hash
Resolves a connector specification to a Hash with keys
:words, :two_words, and :last_word.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tins/duration.rb', line 43 def resolve_connector(connector, style) case connector when nil key = style.is_a?(Symbol) ? style : :abbrev HUMAN_CONNECTORS.fetch(STYLE_DEFAULT_CONNECTOR.fetch(key)) when Symbol then HUMAN_CONNECTORS.fetch(connector) when Hash then connector else raise ArgumentError, "connector must be a Symbol or Hash, got #{connector.class}" end end |