Module: Bible270::Translations
- Defined in:
- lib/bible270/translations.rb
Overview
The translations a reader may choose between, and how each maps onto the external reader's own code. Kept free of Rails so it can be unit tested.
The distinction matters: readers know the NASB 1995 as "NASB95", but Bible Gateway's parameter for it is "NASB1995". Sending the display code straight through would land every link on a search page instead of the passage.
Constant Summary collapse
- VERSIONS =
labelis the full name, for prose.shortis what goes in the select, where "New American Standard Bible 1995" overflows the box. { 'NKJV' => { label: 'New King James Version', short: 'New King James Version', gateway: 'NKJV' }, 'NASB95' => { label: 'New American Standard Bible 1995', short: 'New American Standard 1995', gateway: 'NASB1995' }, 'LSB' => { label: 'Legacy Standard Bible', short: 'Legacy Standard Version', gateway: 'LSB' }, 'ESV' => { label: 'English Standard Version', short: 'English Standard Version', gateway: 'ESV' }, 'KJV' => { label: 'King James Version', short: 'King James Version', gateway: 'KJV' } }.freeze
- DEFAULT =
'NKJV'
Class Method Summary collapse
-
.codes ⇒ Object
The codes offered to readers, narrowed by config.bible_versions if the host only wants some of them.
-
.gateway_code(code) ⇒ Object
The code the external reader expects, which is not always the code readers recognise.
- .label(code) ⇒ Object
- .normalize(code) ⇒ Object
-
.options ⇒ Object
[[label, code], ...] for a select field.
-
.resolve(code) ⇒ Object
Falls back to the configured default, then to ESV, so a link is never built with a blank version.
- .short_label(code) ⇒ Object
- .valid?(code) ⇒ Boolean
Class Method Details
.codes ⇒ Object
The codes offered to readers, narrowed by config.bible_versions if the host only wants some of them.
27 28 29 30 31 |
# File 'lib/bible270/translations.rb', line 27 def codes allowed = Bible270.config.bible_versions if Bible270.config.respond_to?(:bible_versions) requested = Array(allowed).map { |code| code.to_s.upcase }.select { |code| VERSIONS.key?(code) } requested.any? ? requested : VERSIONS.keys end |
.gateway_code(code) ⇒ Object
The code the external reader expects, which is not always the code readers recognise.
51 52 53 |
# File 'lib/bible270/translations.rb', line 51 def gateway_code(code) VERSIONS.dig(normalize(code), :gateway) || normalize(code) end |
.label(code) ⇒ Object
41 42 43 |
# File 'lib/bible270/translations.rb', line 41 def label(code) VERSIONS.dig(normalize(code), :label) end |
.normalize(code) ⇒ Object
37 38 39 |
# File 'lib/bible270/translations.rb', line 37 def normalize(code) code.to_s.strip.upcase end |
.options ⇒ Object
[[label, code], ...] for a select field.
56 57 58 |
# File 'lib/bible270/translations.rb', line 56 def codes.map { |code| ["#{code} — #{short_label(code)}", code] } end |
.resolve(code) ⇒ Object
Falls back to the configured default, then to ESV, so a link is never built with a blank version.
62 63 64 65 66 67 68 69 |
# File 'lib/bible270/translations.rb', line 62 def resolve(code) return normalize(code) if valid?(code) configured = Bible270.config.bible_version if Bible270.config.respond_to?(:bible_version) return normalize(configured) if valid?(configured) codes.include?(DEFAULT) ? DEFAULT : codes.first end |
.short_label(code) ⇒ Object
45 46 47 |
# File 'lib/bible270/translations.rb', line 45 def short_label(code) VERSIONS.dig(normalize(code), :short) || label(code) end |
.valid?(code) ⇒ Boolean
33 34 35 |
# File 'lib/bible270/translations.rb', line 33 def valid?(code) codes.include?(normalize(code)) end |