Class: ArticleJSON::Import::GoogleDoc::HTML::CSSAnalyzer
- Inherits:
-
Object
- Object
- ArticleJSON::Import::GoogleDoc::HTML::CSSAnalyzer
- Defined in:
- lib/article_json/import/google_doc/html/css_analyzer.rb
Instance Attribute Summary collapse
-
#bold_classes ⇒ Object
readonly
Returns the value of attribute bold_classes.
-
#centered_classes ⇒ Object
readonly
Returns the value of attribute centered_classes.
-
#css_parser ⇒ Object
readonly
Returns the value of attribute css_parser.
-
#italic_classes ⇒ Object
readonly
Returns the value of attribute italic_classes.
-
#right_aligned_classes ⇒ Object
readonly
Returns the value of attribute right_aligned_classes.
Instance Method Summary collapse
-
#bold?(class_str) ⇒ Boolean
Check if a given class attribute contains at least one class that makes its text bold.
-
#centered?(class_str) ⇒ Boolean
Check if a given class attribute contains at least one class that centers it.
-
#initialize(css = '') ⇒ CSSAnalyzer
constructor
Initialize the parser with CSS code.
-
#italic?(class_str) ⇒ Boolean
Check if a given class attribute contains at least one class that makes its text italic.
-
#left_aligned?(class_str) ⇒ Boolean
Check if a given class attribute contains no class that sets its alignment to right or center.
-
#right_aligned?(class_str) ⇒ Boolean
Check if a given class attribute contains at least one class that sets its alignment to the right.
Constructor Details
#initialize(css = '') ⇒ CSSAnalyzer
Initialize the parser with CSS code
14 15 16 17 18 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 14 def initialize(css = '') @css_parser = ::CssParser::Parser.new css_parser.load_string!(css) parse end |
Instance Attribute Details
#bold_classes ⇒ Object (readonly)
Returns the value of attribute bold_classes.
6 7 8 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 6 def bold_classes @bold_classes end |
#centered_classes ⇒ Object (readonly)
Returns the value of attribute centered_classes.
6 7 8 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 6 def centered_classes @centered_classes end |
#css_parser ⇒ Object (readonly)
Returns the value of attribute css_parser.
6 7 8 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 6 def css_parser @css_parser end |
#italic_classes ⇒ Object (readonly)
Returns the value of attribute italic_classes.
6 7 8 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 6 def italic_classes @italic_classes end |
#right_aligned_classes ⇒ Object (readonly)
Returns the value of attribute right_aligned_classes.
6 7 8 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 6 def right_aligned_classes @right_aligned_classes end |
Instance Method Details
#bold?(class_str) ⇒ Boolean
Check if a given class attribute contains at least one class that makes its text bold
24 25 26 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 24 def bold?(class_str) (class_str.split(' ') & bold_classes).any? end |
#centered?(class_str) ⇒ Boolean
Check if a given class attribute contains at least one class that centers it
56 57 58 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 56 def centered?(class_str) (class_str.split(' ') & centered_classes).any? end |
#italic?(class_str) ⇒ Boolean
Check if a given class attribute contains at least one class that makes its text italic
32 33 34 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 32 def italic?(class_str) (class_str.split(' ') & italic_classes).any? end |
#left_aligned?(class_str) ⇒ Boolean
Check if a given class attribute contains no class that sets its alignment to right or center
48 49 50 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 48 def left_aligned?(class_str) !right_aligned?(class_str) && !centered?(class_str) end |
#right_aligned?(class_str) ⇒ Boolean
Check if a given class attribute contains at least one class that sets its alignment to the right
40 41 42 |
# File 'lib/article_json/import/google_doc/html/css_analyzer.rb', line 40 def right_aligned?(class_str) (class_str.split(' ') & right_aligned_classes).any? end |