Class: ArticleJSON::Import::GoogleDoc::HTML::CSSAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/article_json/import/google_doc/html/css_analyzer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(css = '') ⇒ CSSAnalyzer

Initialize the parser with CSS code

Parameters:

  • css (String) (defaults to: '')


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_classesObject (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_classesObject (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_parserObject (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_classesObject (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_classesObject (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

Parameters:

  • class_str (String)

Returns:

  • (Boolean)


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

Parameters:

  • class_str (String)

Returns:

  • (Boolean)


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

Parameters:

  • class_str (String)

Returns:

  • (Boolean)


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

Parameters:

  • class_str (String)

Returns:

  • (Boolean)


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

Parameters:

  • class_str (String)

Returns:

  • (Boolean)


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