-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate element definition and parsing: List
Extract general stuff into element class that is supposed to be re-used by other import / export modules.
- Loading branch information
Showing
8 changed files
with
64 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module ArticleJSON | ||
module Elements | ||
class List | ||
attr_reader :type, :content, :list_type | ||
|
||
# @param [Array[ArticleJSON::Elements::Paragraph]] content | ||
# @param [Symbol] list_type | ||
def initialize(content:, list_type: :unordered) | ||
@type = :list | ||
@content = content | ||
@list_type = list_type | ||
end | ||
|
||
# Hash representation of this heading element | ||
# @return [Hash] | ||
def to_h | ||
{ | ||
type: type, | ||
list_type: list_type, | ||
content: content.map(&:to_h), | ||
} | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
describe ArticleJSON::Elements::List do | ||
subject(:element) { described_class.new(**params) } | ||
let(:params) { { content: [content], list_type: :ordered } } | ||
let(:content) do | ||
ArticleJSON::Elements::Paragraph.new( | ||
content: [ArticleJSON::Elements::Text.new(content: 'Foo Bar')] | ||
) | ||
end | ||
|
||
describe '#to_h' do | ||
subject { element.to_h } | ||
it { should be_a Hash } | ||
it { should eq params.merge(type: :list, content: [content.to_h]) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters