Class: LetterOpenerWeb::BaseLetter
- Inherits:
-
Object
- Object
- LetterOpenerWeb::BaseLetter
- Defined in:
- app/models/letter_opener_web/base_letter.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#sent_at ⇒ Object
readonly
Returns the value of attribute sent_at.
Class Method Summary collapse
Instance Method Summary collapse
- #default_style ⇒ Object
- #headers ⇒ Object
-
#initialize(params) ⇒ BaseLetter
constructor
A new instance of BaseLetter.
- #plain_text ⇒ Object
- #rich_text ⇒ Object
- #to_param ⇒ Object
Constructor Details
#initialize(params) ⇒ BaseLetter
Returns a new instance of BaseLetter.
7 8 9 10 |
# File 'app/models/letter_opener_web/base_letter.rb', line 7 def initialize(params) @id = params.fetch(:id) @sent_at = params[:sent_at] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'app/models/letter_opener_web/base_letter.rb', line 5 def id @id end |
#sent_at ⇒ Object (readonly)
Returns the value of attribute sent_at.
5 6 7 |
# File 'app/models/letter_opener_web/base_letter.rb', line 5 def sent_at @sent_at end |
Class Method Details
.find(id) ⇒ Object
17 18 19 |
# File 'app/models/letter_opener_web/base_letter.rb', line 17 def self.find(id) new(id:) end |
.letters_location ⇒ Object
12 13 14 |
# File 'app/models/letter_opener_web/base_letter.rb', line 12 def self.letters_location LetterOpenerWeb.config.letters_location end |
Instance Method Details
#default_style ⇒ Object
45 46 47 |
# File 'app/models/letter_opener_web/base_letter.rb', line 45 def default_style style_exists?('rich') ? 'rich' : 'plain' end |
#headers ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/letter_opener_web/base_letter.rb', line 21 def headers html = read_file(:rich) if style_exists?('rich') html ||= read_file(:plain) # NOTE: This is ugly, we should look into using nokogiri and making that a # dependency of this gem match_data = html.match(%r{<body>\s*<div[^>]+id="container">\s*<div[^>]+id="message_headers">\s*(<dl>.+</dl>)}m) return (match_data[1]).html_safe if match_data && match_data[1].present? 'UNABLE TO PARSE HEADERS' end |
#plain_text ⇒ Object
33 34 35 |
# File 'app/models/letter_opener_web/base_letter.rb', line 33 def plain_text @plain_text ||= adjust_link_targets(read_file(:plain)) end |
#rich_text ⇒ Object
37 38 39 |
# File 'app/models/letter_opener_web/base_letter.rb', line 37 def rich_text @rich_text ||= adjust_link_targets(read_file(:rich)) end |
#to_param ⇒ Object
41 42 43 |
# File 'app/models/letter_opener_web/base_letter.rb', line 41 def to_param id end |