Class: Uniword::Builder::StyleBuilder
- Inherits:
-
Object
- Object
- Uniword::Builder::StyleBuilder
- Defined in:
- lib/uniword/builder/style_builder.rb
Overview
Builds and configures Style objects.
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
-
.from_model(model) ⇒ Object
Wrap an existing Style model.
Instance Method Summary collapse
-
#align(value) ⇒ self
Set paragraph alignment.
-
#bold(value = true) ⇒ self
Set bold.
-
#build ⇒ Object
Return the underlying Style model.
-
#color(value) ⇒ self
Set font color.
-
#font(value) ⇒ self
Set font name.
-
#font_size(points) ⇒ self
Set font size in points.
-
#initialize(name, base_on: "Normal") ⇒ StyleBuilder
constructor
A new instance of StyleBuilder.
-
#italic(value = true) ⇒ self
Set italic.
-
#spacing(before: nil, after: nil, line: nil) ⇒ self
Set paragraph spacing.
-
#type=(value) ⇒ self
Set style type.
Constructor Details
#initialize(name, base_on: "Normal") ⇒ StyleBuilder
Returns a new instance of StyleBuilder.
16 17 18 19 20 21 |
# File 'lib/uniword/builder/style_builder.rb', line 16 def initialize(name, base_on: "Normal") @model = Wordprocessingml::Style.new @model.styleId = name.tr(" ", "") @model.name = Wordprocessingml::StyleName.new(val: name) @model.basedOn = Wordprocessingml::BasedOn.new(val: base_on) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
14 15 16 |
# File 'lib/uniword/builder/style_builder.rb', line 14 def model @model end |
Class Method Details
.from_model(model) ⇒ Object
Wrap an existing Style model
24 25 26 27 |
# File 'lib/uniword/builder/style_builder.rb', line 24 def self.from_model(model) base = model.basedOn&.val || "Normal" new(model.name&.val || model.name.to_s, base_on: base) end |
Instance Method Details
#align(value) ⇒ self
Set paragraph alignment
92 93 94 95 96 |
# File 'lib/uniword/builder/style_builder.rb', line 92 def align(value) ensure_para_props @model.pPr.alignment = value.to_s self end |
#bold(value = true) ⇒ self
Set bold
52 53 54 55 56 |
# File 'lib/uniword/builder/style_builder.rb', line 52 def bold(value = true) ensure_run_props @model.rPr.bold = Properties::Bold.new(value: value) self end |
#build ⇒ Object
Return the underlying Style model
114 115 116 |
# File 'lib/uniword/builder/style_builder.rb', line 114 def build @model end |
#color(value) ⇒ self
Set font color
72 73 74 75 76 |
# File 'lib/uniword/builder/style_builder.rb', line 72 def color(value) ensure_run_props @model.rPr.color = Properties::ColorValue.new(value: value) self end |
#font(value) ⇒ self
Set font name
82 83 84 85 86 |
# File 'lib/uniword/builder/style_builder.rb', line 82 def font(value) ensure_run_props @model.rPr.font = value self end |
#font_size(points) ⇒ self
Set font size in points
42 43 44 45 46 |
# File 'lib/uniword/builder/style_builder.rb', line 42 def font_size(points) ensure_run_props @model.rPr.size = Properties::FontSize.new(value: points.to_i * 2) self end |
#italic(value = true) ⇒ self
Set italic
62 63 64 65 66 |
# File 'lib/uniword/builder/style_builder.rb', line 62 def italic(value = true) ensure_run_props @model.rPr.italic = Properties::Italic.new(value: value) self end |
#spacing(before: nil, after: nil, line: nil) ⇒ self
Set paragraph spacing
104 105 106 107 108 109 110 111 |
# File 'lib/uniword/builder/style_builder.rb', line 104 def spacing(before: nil, after: nil, line: nil) ensure_para_props @model.pPr.spacing ||= Properties::Spacing.new @model.pPr.spacing.before = before if before @model.pPr.spacing.after = after if after @model.pPr.spacing.line = line if line self end |
#type=(value) ⇒ self
Set style type
33 34 35 36 |
# File 'lib/uniword/builder/style_builder.rb', line 33 def type=(value) @model.type = value self end |